从laravel中的数据透视表中删除行

时间:2019-11-28 07:23:21

标签: laravel

我有表(projects, roles, scopes, shifts, users)和表(project_role_scope_shift_user)作为枢轴。

我要删除特定行,例如:

[project_id = 1 , scope_id = 2 , ... ]

但是,分离方法无法正常工作。

$user->roles()->detach(role)      !not working   => removes all rows of that role

$user->roles()->detach(role, ['project_id' => $projectId, 'scope_id' => $scopeId, 'shift_id' => $shiftId]);  => this does not work too, removes all rows of that role

1 个答案:

答案 0 :(得分:1)

尝试一下:

$user->roles()->wherePivot(['project_id' => $projectId, 'scope_id' => $scopeId, 'shift_id' => $shiftId])->detach(); 
相关问题