laravel - 从 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
解决方案
尝试这个 :
$user->roles()->wherePivot(['project_id' => $projectId, 'scope_id' => $scopeId, 'shift_id' => $shiftId])->detach();
推荐阅读
- google-cloud-platform - Google Cloud Build 未能检索到 Github 存储库
- authentication - 如何配置 axios 以使用 auth 请求 WebAPI?
- python - 如何用数据框列中的字符串列表替换单个字符串
- vue.js - Vuetify数据表如何使用主题颜色设置全选列的背景颜色?
- javascript - 如何替换javascript中所有出现的字符串?
- javascript - 关于英国政府新的外出就餐帮助计划网站的问题
- linux - 如何在 windows 和 linux 上为 react-native 项目运行 detox?
- c# - 如何在 CIL (MSIL)“调用实例 void valuetype [..type]”中返回或保存值?(通用中间语言)
- javascript - 表单中的下拉列表在使用节点 js 提交后清除值
- r - 检查变量并根据组归属对其进行分组