Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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
Laravel 基于关系的拉威尔滤波器_Laravel_Eloquent - Fatal编程技术网

Laravel 基于关系的拉威尔滤波器

Laravel 基于关系的拉威尔滤波器,laravel,eloquent,Laravel,Eloquent,嗨,我和这3个模型有这种关系 顾客 <?php namespace App; use Illuminate\Database\Eloquent\Model; class Customers extends Model { public $primaryKey = 'id'; protected $fillable = [ 'contr_nom', 'contr_cog', 'benef_nom', 'be

嗨,我和这3个模型有这种关系

顾客

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customers extends Model
{
    public $primaryKey = 'id';
    protected $fillable = [
        'contr_nom',
        'contr_cog',
        'benef_nom',
        'benef_cog',
        'email',
        'polizza',
        'targa',
        'iban',
        'int_iban',
        'cliente',
    ];

    public function claims()
        {
            return $this->hasMany(Claims::class);
        }
        
    public function refunds()
    {
        return $this->hasManyThrough(Refunds::class, Claims::class);
    }

}
它可以工作,我可以获得每个档案的客户信息(父表)(我放在datatables中) 但我无法根据退款表插入另一个筛选器。 我只需要出示档案

['status_ref', '>',4]
问题是状态_ref在退款表中

我试着做这样的事,但没有效果

    $data =  Claims::with(array('customers'=>function($query){
        $query->select('id','contr_nom','contr_cog','targa','email','gcliente');
    }))->refunds()
    ->where('status_ref', '>',4)
     ->get();
我不明白为什么。。。。
Thx

您必须使用
其中的
类似:

$data =  Claims::with(array('customers'=>function($query){
           $query->select('id','contr_nom','contr_cog','targa','email','gcliente');
         }))
         ->whereHas('refunds', function (Builder $query) {
           $query->where('status_ref', '>', 4);
         })
         ->get();
['status_ref', '>',4]
    $data =  Claims::with(array('customers'=>function($query){
        $query->select('id','contr_nom','contr_cog','targa','email','gcliente');
    }))->refunds()
    ->where('status_ref', '>',4)
     ->get();
$data =  Claims::with(array('customers'=>function($query){
           $query->select('id','contr_nom','contr_cog','targa','email','gcliente');
         }))
         ->whereHas('refunds', function (Builder $query) {
           $query->where('status_ref', '>', 4);
         })
         ->get();