I have a relationship in a model FeeModuleModel as shown below
public function heads()
{
return $this->hasMany('App\Models\FeeHeadModel','location_id','id');
}
and in my controller file i need to fetch only the values FeeModuleModel where the FeeHeadModel has type as unstructured My controller code is as shown below
$modules = FeeModuleModel::where('vt_ay_id', '=', Session::get('sess_ay_id'))->with(['heads'=>function($q){
$q->where('type','=','unstructured');
}])->orderby('priority', 'asc')->get();
This fails with the following error
Call to a member function getRelationExistenceQuery() on array
What is the problem with my code and what I can do to solve it