【发布时间】:2022-10-18 05:04:36
【问题描述】:
这是我尝试编写的查询并给出了错误
$users =User::has('subscriptions', function (Builder $q) {
$q->whereNotNull('ends_at');
})->get();
收到此错误
SQLSTATE[42601]: Syntax error: 7 ERROR: SELECT * with no tables specified is not valid LINE 1: ...sers"."id" = "subscriptions"."user_id") = (select * where "e... ^ (SQL: select * from "users" where (select count(*) from "subscriptions" where "users"."id" = "subscriptions"."user_id") = (select * where "ends_at" > now) and "users"."deleted_at" is null)
当我编写此代码时,我得到了结果,但需要过滤结果以获取订阅用户的列表,而无需调用 User::all() 然后循环过滤。
User::has('subscriptions')->get();
【问题讨论】:
标签: php mysql laravel eloquent laravel-8