paginate - Laravel Get products from multiple taxonomies -
paginate - Laravel Get products from multiple taxonomies -
i have 3 tables, products, taxonomies , product_taxonomy. 3rd table pivot table contains product_id , taxonomy_id, meaning product , taxonomy many many relationship. given list of taxonomy ids, how can products belong these taxonomies? note: want have products result set beingness able paginated or order maybe it's cost or something.
you need create many-to-many
relationship , requires relationship methods like:
// product model public function taxonomies() { homecoming $this->belongstomany('taxonomy'); } // taxonomy model public function products() { homecoming $this->belongstomany('product'); }
the query:
$listoftaxonomyids = [1,2,3]; $products = product::wherehas('taxonomies', function($query) utilize ($listoftaxonomyids){ $query->wherein('taxonomy_id', $listoftaxonomyids); })->get();
laravel paginate
Comments
Post a Comment