dev-master
9999999-devEasy breadcrumb generation
MIT
The Requires
by Kelly Kiernan
Wallogit.com
2017 © Pedro Peláez
Easy breadcrumb generation
, (*1)
First, install the package via composer:, (*2)
composer require kkiernan/breadcrumbs
If using Laravel, add the service provider and alias to config/app.php., (*3)
'providers' => [
Kiernan\Breadcrumbs\ServiceProvider::class,
],
'aliases' => [
'Breadcrumbs' => \Kiernan\Breadcrumbs\Facade::class,
]
Add breadcrumbs as needed before rendering your view:, (*4)
Breadcrumbs::add('Posts', action('PostsController@index'));
Breadcrumbs::add('New Post');
Add many breadcrumbs at once if you prefer:, (*5)
Breadcrumbs::addMany([
['Posts', action('PostsController@index')],
['New Post']
]);
A Bootstrap partial is included to display your breadcrumbs. If using Laravel Blade, you can include the partial in your template:, (*6)
@include('kkiernan::breadcrumbs');
If you'd like to edit the partial, publish it to resources/views/vendor/kkiernan:, (*7)
php artisan vendor:publish --tag=kkiernan
Breadcrumbs can be added dynamically, which is helpful when multiple pages link to a particular page. For example, imagine that both a dashboard and a list of posts link to a post detail view. Consider the following Laravel-centric example in which the first breadcrumb will render as either "Dashboard" or "Posts" depending on the referring page., (*8)
// DashboardController@index...
Breadcrumbs::put('posts', 'Dashboard', action('DashboardController@index'));
// PostsController@index...
Breadcrumbs::put('posts', 'Posts', action('DashboardController@index'));
// PostsController@show...
Breadcrumbs::addDynamic('posts');
Breadcrumbs::add($post->title);
If you need to unset a dynamic crumb and prevent it from rendering, simply call the forget method:, (*9)
Breadcrumbs::forget('posts');
Easy breadcrumb generation
MIT