其中Laravel 5.8中hasMany关系具有条件

问题描述 投票:0回答:1

我在模型FeeModuleModel中具有关系,如下所示

   public function heads()
   {
       return $this->hasMany('App\Models\FeeHeadModel','location_id','id');
   }

并且在我的控制器文件中,我只需要获取FeeHeadModel类型为非结构化类型的值FeeModuleModel我的控制器代码如下所示

$modules = FeeModuleModel::where('vt_ay_id', '=', Session::get('sess_ay_id'))->with(['heads'=>function($q){ 
            $q->where('type','=','unstructured');
        }])->orderby('priority', 'asc')->get();

此操作失败,并出现以下错误

在数组上调用成员函数getRelationExistenceQuery()

我的代码有什么问题,我该怎么解决

eloquent laravel-5.8 eloquent--relationship php-7.3 wherehas
1个回答
0
投票

请将此代码更改为此代码

$modules = FeeModuleModel::with(['heads'=>function($q){ 
            $q->where('type','=','unstructured');
        }])->where('vt_ay_id', '=', Session::get('sess_ay_id'))->orderby('priority', 'asc')->get();
© www.soinside.com 2019 - 2024. All rights reserved.