antonio21061995's avatar

View product by categories with laravel

Hi, I have a problem. I'm developing an e-commerce site for sales of musical instruments. I managed the backend part with the addition of products with various categories (eg flutes, saxophones, clarinets, guitars, etc.) now I have a product display page called product.blade.php now when for example I from my template I click on the flutes category, how can I display only products with id_category flute on my product.blade.php page?

0 likes
1 reply
devit.gg's avatar

What I would do personally, not sure if it's the best route ¯_(ツ)_/¯.

I'd render the products.blade with a @switch($category) .. if its count() == 0 .. Page is an initial render through a initial render route 'my products'.. once a user selects a category, you render page back to same blade because of the @switch ... but u pass $catgeory collection back this time... which will trigger the @switch($category) to display whatever it is..

then just @foreach($category as $categoryItem) and display your products.

Please or to participate in this conversation.