0

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

Asish Antony
  • 85
  • 2
  • 11

1 Answers1

0

Please change your code to this one

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