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

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -