Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel wherenotexists返回null_Php_Mysql_Laravel_Eloquent - Fatal编程技术网

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列。我一直在学习这个例子