more

How do I make a selection from two related tables?

Posted On
Posted By Layla Brooks

I have a table with products, relation to the tables of categories and collections as many to many. I need to make a selection by category and collection so that I get the products that are included there

I have written some selection, but it does not take into account that the products are related with collections and categories.

$filter_collections = [1, 3];
$filter_categories = [2, 5];


$products = Product::whereHas('collection', function ($query) use ($filter_collections) {
                $query->whereIn('collection_id', $filter_collections);
            })->whereHas('category', function ($query) use ($filter_categories) {
                $query->whereIn('category_id', $filter_categories);
            })->get();

How do I make the selected products belong to the specified categories and collections?

Related Post

Latest Post

MTHFR Gene Test: Clearing the Confusion Once and For All
Health

MTHFR Gene Test: Clearing the Confusion Once and For All

Read More
Posted On
Fitness Professional Insurance
Health and Fitness

Fitness Professional Insurance Tips for Trainers: Liability, Property, and Online Coverage

Read More
Posted On
White Sapphire vs Lab Grown Diamonds: A Modern Comparison
more

White Sapphire vs Lab Grown Diamonds: A Modern Comparison

Read More
Posted On
lab grown diamonds
jewellery

The New Era of Diamond Jewelry: The Rise of Lab Grown Diamonds

Read More
Posted On
Moissanite Diamond
jewellery

Moissanite Diamond vs Lab Made Diamonds: Which Sparkles Brighter?

Read More
Posted On