samedi 27 avril 2019

Laravel get product in multiple category

Every products will have multiple category. The structure of DB as follow:

1. Product Table: category_ids //2,3,5
2. Category: id, title, etc.

This is my current way to get the product, which will join another table and get some data.

$products = Product::where('status', StatusConstant::PT_ACTIVE)
                                ->with(['joindraw' => function ($query){
                                        $query->where('user_id', $this->user->id);
                                }])->get();

I will need to have a page, with tabs to get the product in the respective category (tab). What's the most effective way to get it? My idea is to get the category and foreach the products which has the category id.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2ZFRWZ9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire