【发布时间】:2019-02-03 19:42:03
【问题描述】:
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 )
【问题讨论】:
-
你能举一个你想写的子查询的例子吗?
标签: php mysql laravel eloquent exists