binggle's avatar

How to filter with Many-to-Many relation ?

I have two models of Many to Many.

Site / Banner

So there is banner_site pivot table.

Banner model has banner_type.

So I want get site with banners which is filtered by banner_type

But this is not working. It does not filter and get s all banners.

What is wrong with this and how can I filter ?


$site = Site::query()
                ->with(['banners'=> function($query) {
                    $query->where('banner_type', $this->banner_type);
                }])
                ->find( $site_id );
0 likes
1 reply

Please or to participate in this conversation.