yasiao / laravel-breadcrumb
A simple breadcrumbs generator.
Installs: 1 430
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
README
A simple breadcrumb generator.
Installation
composer require yasiao/laravel-breadcrumb
Configuration
config/app.php
providers:
Yasiao\Breadcrumb\BreadcrumbServiceProvider::class
aliases:
'Breadcrumb' => Yasiao\Breadcrumb\BreadcrumbFacade::class
config/breadcrumb.php
php artisan vendor:publish
return [ 'breadcrumb-file-path' => app_path('Http/breadcrumb.php'), 'default-template' => 'breadcrumb::bootstrap4', 'ignore-undefined-breadcrumb' => false ];
Base Usage
-
Create the breadcrumb file in the "breadcrumb-file-path".
-
Define breadcrumbs in the breadcrumb file.
Without parameters:
// Home Breadcrumb::define('home', function ($breadcrumb) { $breadcrumb->add('Home', action('HomeController@index')); });
With a parameter:
// Home > $category->title Breadcrumb::define('category', function ($breadcrumb, $category) { $breadcrumb->add('Home', action('HomeController@index')); $breadcrumb->add($category->title, $category->url); });
With parameters:
// Home > $category['title'] > $content->title Breadcrumb::define('content', function ($breadcrumb, $category, $content) { $breadcrumb->add('Home', action('HomeController@index')); $breadcrumb->add($category['title'], $category['url']); $breadcrumb->add($content->title, $content->url); });
-
Render breadcrumbs.
Without parameters:
{!! Breadcrumbs::render('home') !!}
With a parameter:
{!! Breadcrumbs::render('home', $category) !!}
With parameters:
{!! Breadcrumbs::render('home', $category, $content) !!}
Advanced Usage
-
The breadcrumb use the special template.
{!! Breadcrumbs::setTemplate('bootstrap3')->render('home') !!}