【发布时间】:2019-06-26 23:52:26
【问题描述】:
public function edit($id){
$guests=Guest::with('programs', 'specialties')->find($id);
return view('editform',compact('guests'));
}
public function update(Request $request, $id)
{
$guestupdate = Guest::find($id);
$guestupdate->programs()->update($request->all());
$guestupdate->specialties()->update($request->all());
return redirect('/home/show'.$id)->with('alert', 'You have successfully updated');
}
class Guest extends Model
{
protected $primaryKey = 'guest_id';
protected $table = 'guests';
protected $fillable =
['guest_fname','guest_lname','profession','mobile','work_phone',
'current_job','previous_job','work_address','DOB','DD','program_name','specialty_name'];
public function programs()
{
return $this->belongsToMany(Program::class, 'guest_show', 'guest_id', 'program_id')
->withPivot('subject', 'show_date');
}
public function specialties()
{
return $this->belongsToMany(Specialization::class, 'guest_speciality', 'guest_id', 'speciality_id');
}
class Program extends Model
{
protected $table = 'programs';
protected $primaryKey = 'program_id';
protected $fillable = ['program_name','subject','show_date'];
public function guests()
{
return $this-
>belongsToMany(Guest::class,'guest_show','program_id','guest_id')
->withPivot('subject', 'show_date');
}
}
class Specialization extends Model
{
protected $table = 'specialties';
protected $primaryKey = 'specialty_id';
protected $fillable = ['specialty_name'];
public function guests()
{
return $this-
>belongsToMany(Guest::class,'guest_speciality','speciality_id','guest_id');
}
这是我用于编辑数据的控制器和模型代码(仅由 guest_id 显示)然后我将更新请求所有字段从多对多关系。 编辑 URL 为 true,但是当我单击按钮更新数据时出现此问题列未找到:1054 Unknown column '_token' in 'field list' (SQL: update what's solve?
【问题讨论】:
-
您可以在错误消息中添加您返回的查询吗?
-
hdifen这个查询更新
programs内部联接guest_show上programs。program_id=guest_show。program_id组_token= LiQTnFrnk8Vb96XS7ovyYmmBJJjpweiI71fV7R24,guest_fname=محمد,guest_lname=فهمي,profession=فاحصجودة,mobile= 796548234,work_phone= 69832511,current_job=شركةمكامن,previous_job=شركةمكامن,work_address=عمان,DOB= 1988- 11-03,DD987654339 @ =نبیالبلی,specialty_name987654340subject987654341 @ =جودةدةنابيبالنفط,show_date= 2018-10-30,updated_at= 2019-02-03 06:55:26 其中guest_show.guest_id= 3) -
@AlaaSalah 检查我的更新答案。