Laravel Eloquent ->whereHas()
使用 exists()
子查询 - https://dev.mysql.com/doc/refman/8.0/en/exists-and-not-exists-subqueries.html - 为了返回您的结果。
我想写我自己的子查询,但我不知道如何告诉 Eloquent -> 它在哪里。
如果我这样做:
$query->where( DB::raw(' exists( subquery ) ')
Laravel 将子查询写成:
where exists( subquery ) is null
所以我只是想知道可以使用什么 $query->method()
将 exists() 子查询添加到“where”语句。子查询与 laravel 生成的类型相同,但写成:
... and exists ( select * from `tbl` inner join `assets` on `custom_assets`.`id` = `tbl`.`asset_id` where `assets`.`deleted_at` is null and `users`.`id` = `assets`.`client_id` and `field_id` = ? and (`value` = ? and `assets`.`deleted_at` is null )
最佳答案
使用whereRaw()
:
$query->whereRaw('exists( subquery )')
关于php - laravel eloquent ->whereHas - 编写你自己的存在(子查询),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52070297/