Php Laravel wherenotexists返回null
我有下面的代码Php Laravel wherenotexists返回null,php,mysql,laravel,eloquent,Php,Mysql,Laravel,Eloquent,我有下面的代码 $not_paid = Tenant::where('property_id', $property_id) ->whereNotExists(function ($query) use ($property_id) { $query->select('user_id') ->from('rent_paids'); }) -
$not_paid = Tenant::where('property_id', $property_id)
->whereNotExists(function ($query) use ($property_id) {
$query->select('user_id')
->from('rent_paids');
})
->get();
它应该获取某个属性中的所有租户,在租金支付
表中查找他们,并返回不在租金支付
表中的用户,如下所示:
租户表
身份证件
用户id
物业编号
1.
1.
1.
2.
2.
1.
3.
3.
1.
您缺少where子句将其绑定回原始表
$not_paid = Tenant::where('property_id', $property_id)
->whereNotExists(function ($query) use ($property_id) {
$query->select('user_id')
->from('rent_paids')
->whereColumn('tenants.user_id', '=', 'rent_paids.user_id');
})
->get();
您缺少where子句将其绑定回原始表
$not_paid = Tenant::where('property_id', $property_id)
->whereNotExists(function ($query) use ($property_id) {
$query->select('user_id')
->from('rent_paids')
->whereColumn('tenants.user_id', '=', 'rent_paids.user_id');
})
->get();
->whereNotExists()
不接受2个值/参数吗?Where notexists()接受2个值/参数吗?@DimitriMostrey否,a不->whereNotExists()?不存在于何处?@DimitriMostrey不,a我认为这需要whereColumn
,尽管它看起来像join
可能比wherenotesists
更合适。另外,它可能需要与$property\u id
绑定,但从这个问题来看,它是如何绑定的还不清楚。你是对的,它确实需要是where列。我一直在遵循上的示例,我认为这需要whereColumn
,尽管它看起来像是join
可能比whereNotExists
更合适。另外,它可能需要与$property\u id
绑定,但从这个问题来看,它是如何绑定的还不清楚。你是对的,它确实需要是where列。我一直在学习这个例子