You need to define the relationship:
public function songs_number(){
return $this->belongsTo('App\Songs');
}
I did but... this still doesn't work. I get the same error. How can I apply the method/filter from my route?
Route::get('/artist_list', function () {
$artists = Artists::with(['songs_number'=>function($query){
$query->where('songs_number.songs_number',100); // second songs_number should match your column field
}])->get();
});
Yes, I already do this... but since my query is very complex (this was just an example), and I have to use it many times, I was wondering if it was possible to use a model method instead of repeating the same filter over and over
hi if you definition songs function in your artist model like this: public function songs() { return $this->hasMany('App\Song'); }
you can fetch artists that have exactly 100 songs with this query
Artists::has('songs', '=', 100)->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community