.jpg)
Hello! How can we help you?
Find interesting products, stories and categories tailored for you.
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.
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.
Route sahi bana hua hona chahiye:
php
CopyEdit
Route::get('/show-brands/{id}', [BrandController::class, 'showBrands'])->name('show.brands');
Yeh bhi perfect hai.
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:
category_id
empty ya galat hoCheck 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.
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.
Be the first to know. Subscribe today and unlock exclusive deals!
Free support line!
Orders Support!
Working Days / Hours!