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.
$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
Post a Comment