php - method not found laravel model -


i have 2 model, jadwalterapisklinik , pesertaklinik.

i try call data using code :

$data = jadwalterapisklinik::wherehas('pesertaklinik', function($q){                 $q->wherehas('timecontrolling', function($qq){                     $qq->where('status', 'done');                 });             })->with(['pesertaklinik' => function($q){                 $q->with(['timecontrolling' => function($qq){                     $qq->where('status', 'done');                 }]);             }])->orderby('tanggal', 'desc')->get();     $data = $data->pesertaklinik()->paginate(10); 

but result "method pesertaklinik not exist."

this method pesertaklinik in jadwalterapisklinik model :

public function pesertaklinik(){     return $this->hasmany(pesertaklinik::class, 'jadwal_terapis_id'); } 

but when use find(1) on first query not get() , working fine.

structure model : jadwalterapis has many pesertaklinik, pesertaklinik has 1 timecontrolling.

whats wrong code ? thank in advance.

you should use get() => execute query or paginate() => execute query , paginate results. not both chained.

you can use command tosql() instead get() check whether query written way should be.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -