Breadcrumbs (or breadcrumb trail) is a secondary navigation system that shows a user’s location on a site or web app. Here we are going to see how to create breadcrumbs in bagisto.
How to create Breadcrumbs in Bagisto
The following examples should make it clear:
1. First, we need to create a breadcrumb.php file in the routes folder.
The most simple breadcrumb is probably going to be your homepage, which will look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php use Diglactic\Breadcrumbs\Breadcrumbs; use Diglactic\Breadcrumbs\Generator as BreadcrumbTrail; // Home Breadcrumbs::for('home', function ($trail) { $trail->push('Home', route('shop.home.index')); }); // Category Breadcrumbs::for('category', function ($trail,$category) { $trail->parent('home'); $trail->push($category->name, route('shop.productOrCategory.index', $category->url_path)); }); |
As you can see, you simply call $trail->push($title,$url) inside the closure.
For generating the URL, you can use any of the standard Laravel URL-generation methods, including:
1. (‘path/to/route’)(URL::to())
2. secure_url(‘path/to/route’)
route(‘routename’)
or route(‘routename’,
‘param’) or route(‘routename’,
[‘param1’, ‘param2’]) (URL::route())
3. action(‘controller@action’)
(URL::action())
Here it must be clear that the breadcrumb data should be unique. For the visibility of the data clearly in the frontend UI, it must have unique information.
And also the trail push Name and Route be set accordingly so that the data which is to be applied to the breadcrumb should work as per our need.
2. Second, these details must be added to the blade file.
Index.blade.php which is inserted on the home page.
This example would be rendered like this:
1 2 3 |
@section('full-content-wrapper') {{ Breadcrumbs::render('home') }} @section('content-wrapper') {{ Breadcrumbs::render('category',$category) }} <category-component></category-component> |
And results in this output:
Check out the Parent links
This is another static page, but this has a parent link before it:
It works by calling for the closure for the home
breadcrumb defined above.
It would be rendered like this:
And results in this output:
Note that the default templates do not create a link for the last breadcrumb (the one for the current page), even when a URL is specified. You can override this by creating your own template.
So, that was much about the article “ How to Create Breadcrumb in Bagisto ”. Also for any queries or doubts reach out to us at support@webkul.com. You can also raise a ticket at our HelpDesk System.