我在Organization.php中有此模型
public function agency()
{
return $this->belongsToMany('App\Agency')->withPivot('status');
}
以及Agency.php中的此模型
public function organizations()
{
return $this->belongsToMany('App\Organization')->withPivot('status');
}
如何更新数据透视表中特定行的状态? 这是我在控制器中的代码:
public function removeAgency(Request $request){
$my_agencies = Organization::find($request['org_id']);
$member = $my_agencies->agency()
->where('agency_organization.agency_id', $request['agency_id'])
->first();
$member->pivot->status = 'removed';
$member->pivot->save();
}
它返回一条错误消息:“从空值创建默认对象”