💬
WhatsApp Support

Hello! How can we help you?

php slider

Find interesting products, stories and categories tailored for you.

Documentry

Here Documentry write about create item

zs ds af wds s  dsf sdzx

 

Bilkul, bro! Chalo step by step check karte hain ke problem kaha ho sakti hai. Tum keh rahe ho:

Jab tum category pe click karte ho aur next page pe jatay ho, to tumhain sirf usi category ke related brands dikhne chahiye — lekin wo nahi ho raha.

Mujhe tumhara blade file ka code mila hai jahan pe brands list ho rahe hain, aur controller ka showBrands method bhi mil gaya hai. Let’s do some debugging.


✅ Step 1: Category Click Link Check

Pehle ye confirm kar lein ke category pe click krne se sahi ID ja rahi hai ya nahi.

Blade file (category listing) me:


 

blade

CopyEdit

<a href="{{ route('show.brands', $category->id) }}">{{ $category->name }}</a>

Ye sahi lag raha hai. Is se route /show-brands/{id} call ho raha hai.


✅ Step 2: Route Check

Route sahi bana hua hona chahiye:


 

php

CopyEdit

Route::get('/show-brands/{id}', [BrandController::class, 'showBrands'])->name('show.brands');

Yeh bhi perfect hai.


✅ Step 3: Controller Logic

Controller me tumhara logic kuch is tarah hai:


 

php

CopyEdit

public function showBrands($id) { $category = Category::findOrFail($id); $brands = Brand::where('category_id', $id)->get(); return view('brands.show', compact('category', 'brands')); }

Yeh bhi sahi lag raha hai — lekin problems ho sakti hain agar:

1. Brand table me category_id empty ya galat ho

Check karo brands table me har brand ke andar category_id sahi saved hai ya nahi.


 

sql

CopyEdit

SELECT * FROM brands WHERE category_id = X;

Agar empty aata hai to where('category_id', $id) koi record return nahi karega.


✅ Step 4: Database Relationship Check

Check karo Brand model me ye relation hai:


 

php

CopyEdit

public function category() { return $this->belongsTo(Category::class); }

Aur brands table me foreign key category_id hai.

0  Comments

Sign up for Newsletters

Be the first to know. Subscribe today and unlock exclusive deals!

888 345 6789

Free support line!

Support@posthemes.com

Orders Support!

Mon - Fri / 8:00 - 18:00

Working Days / Hours!