mercredi 2 décembre 2020

How to do the breadcrumbs with passing id using davejamesmiller in Laravel

I using davejamesmiller/laravel-breadcrumbs package for the breadcrumbs I facing one issue that was I have one Sub-Category it's assigned to two different Top-Category It's like this.

Top Category = Apparel(1) Hoodies(2)

Sub Category = Hoodies(1) Hoodies(1)

If I click the Hoodies on Apparel Breadcrumb have to show like this Home / Apparel / Hoodies. In URL I just passing the Sub Category ID only. How can I identify that clicked subcategory belongs to which top category. Please help me to fix this issue. I attached the breadcrumbs.php file code.

<?php

// Home
use App\top_level_category;

Breadcrumbs::for('Home', function ($trail) {
    $trail->push('Home', route('Home'));
});

// Top Category
Breadcrumbs::for('Category', function ($trail, $id) {
    $topCate = top_level_category::where('tolc_seo_title',$id)->first();
    $trail->parent('Home');
    $trail->push($topCate->tolc_name, route('Category', $topCate));
});

// Sub Category
Breadcrumbs::for('Sub_Category', function ($trail, $id) {
    $subCate = sub_category_one::where('suco_seo_title',$id)->first();
    $trail->parent('Home');
    //Here Have to come top category which I click
    $trail->push($subCate->suco_name, route('Sub_Category', $subCate));
});

<div class="breadcrumb">
    <ul>
       <li>
          {!! Breadcrumbs::render() !!}
       </li>
    </ul>
</div>


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire