![](/img/trans.png)
[英]Laravel Eloquent SQLSTATE[23000]: Integrity constraint violation: 1052 Column ... in where clause is ambiguous
[英]SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous
我收到此錯誤:
(3/3) QueryException
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'value' in where clause is ambiguous (SQL: select * from `users` where exists (select * from `permission_templates` inner join `permissions` on `permission_templates`.`value` = `permissions`.`value` where `users`.`id` = `permissions`.`user_id` and (`value` = TICKET_LIST or `value` = MASTER) and `permission_templates`.`deleted_at` is null) and `id` != 3 and `users`.`deleted_at` is null)
如果我運行這個
$collaborators = User::whereHas('permissions', function($query) {
$query->where('value', 'TICKET_LIST')
->orWhere('value', 'MASTER');
})->where('id', '!=', Auth::id())
->get();
看起來您的用戶表中有一個名為“值”的列。
要解決此問題,您只需在列名之前添加表名,
$collaborators = User::whereHas('permissions', function($query) {
$query->where('permissions.value', 'TICKET_LIST')
->orWhere('permissions.value', 'MASTER');
})->where('id', '!=', Auth::id())
->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.