Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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 5.8 withCount()忽略我的where语句_Php_Laravel - Fatal编程技术网

Php Laravel 5.8 withCount()忽略我的where语句

Php Laravel 5.8 withCount()忽略我的where语句,php,laravel,Php,Laravel,我试图找到代理系统中候选人的具体合规项的数量 当我使用with()时,它返回1个正确的结果,但当我使用withCount()时,它返回所有符合项的数量,并忽略where语句 候选模型: <?php namespace App; use Illuminate\Database\Eloquent\Model; class Candidate extends Model { protected $table = 'candidates'; public function

我试图找到代理系统中候选人的具体合规项的数量

当我使用with()时,它返回1个正确的结果,但当我使用withCount()时,它返回所有符合项的数量,并忽略where语句

候选模型:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Candidate extends Model
{
    protected $table = 'candidates';

    public function complianceItemsActive()
    {
        return $this->hasMany('App\CandidateComplianceItem', 'candidate_id', 'id')
            ->where('valid_until', '>=', date('Y-m-d'))
            ->orWhereNull('valid_until');
    }
}

我可能错了,但我想这可能和你们关系中的附加条款有关。我建议将这些条款嵌套,以便它们不会与您稍后添加的条款冲突:

public function complianceItemsActive()
{
    return $this->hasMany('App\CandidateComplianceItem', 'candidate_id', 'id')
        ->where(function ($query) {
            $query->where('valid_until', '>=', date('Y-m-d'))->orWhereNull('valid_until');
        });
}

我可能错了,但我想这可能和你们关系中的附加条款有关。我建议将这些条款嵌套,以便它们不会与您稍后添加的条款冲突:

public function complianceItemsActive()
{
    return $this->hasMany('App\CandidateComplianceItem', 'candidate_id', 'id')
        ->where(function ($query) {
            $query->where('valid_until', '>=', date('Y-m-d'))->orWhereNull('valid_until');
        });
}
public function complianceItemsActive()
{
    return $this->hasMany('App\CandidateComplianceItem', 'candidate_id', 'id')
        ->where(function ($query) {
            $query->where('valid_until', '>=', date('Y-m-d'))->orWhereNull('valid_until');
        });
}