php - Laravel 5 scope not working -


i have following scope:

public function scopelabel($query, $label) {     return $query->with(['label' => function ($q) use ($label) {         $q->where('name', '=', $label)->get();     }]); } 

which use follows:

$appointments = appointment::latest('created_at')->label($label)->get(); 

the $label fetched post form , matches name field of labels table.

the above query works when call directly controller, so:

    appointment::with(['label' => function ($q) use ($label) {         $q->where('name', '=', $label)->get();     }])->get(); 

this returns results appointments table, appointments.label_id matches labels.id in labels table. hope you're still me :)

but when use query in scope, above, doesn't work. returns results, , cannot seem figure out why is. pointers?

answered once, similar issue had, , didn't learn it, shame on me.

laravel search relationship

        $appointment = app\appointment::wherehas('label', function ($query) use ($label){             $query->where('name', '=', $label);         })             ->with(['status' => function($query) use ($label){                 $query->where('name', '=', $label);             }])->get(); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -