Jul 23, 2017
0
Level 17
BelongsToMany filtering query
I have 2 models. User, Styles[id|name].
Relationships are as following:
// in user class
public function styles() {
return $this->belongsToMany('App\Styles', 'user_style', 'user_id', 'style_id');
}
// in styles class
public function users() {
return $this->belongsToMany('App\User');
}
When filtering, visitors can select different styles and filter to see only users with those styles. The filter names are passed in the URL (for SEO purposes)
http://site.dev/users?city=&style=Style1,Style2
Can you please assist with the query that will return only users that have at least one of those styles.
Please or to participate in this conversation.