displaying the brands in filter panel for a ecommerce site

Posted 9 months ago by Shawdow


i need to display the brand for a particular products i explored in the some ecomerce site filter panel was changing as the products gets displayed

i have brand table now i need know the how the brands get displayed for every product

in the brands table

id        name           category_id 
1           hp                      1
2         sony                    1

in the categories table

id           name                       parent_id 
1             electronics                 null 
2           house appliances      null
3            laptops                            1

logic i have written if there is any wrong please correct me

in the controller

public function filterCategory() {

$category = DB::table('categories')->select('id')->get();    

$brand = DB::table('brands')->select('*')->get();

return view('category',compact('category','brand));


in the blade file

@foreach($category as $categories)

@foreach($brand as $brands)

if($categories->id as $brands->category_id)

Brand:{{ $brands->name }}


Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.