davejamesmiller/laravel-breadcrumbs A simple Laravel-style way to create breadcrumbs in Laravel 5.
This project is a very simple demo to show you how to use Laravel Breadcrumbs quickly.
This project was created by The EST Group and PHPHub.
You can refer to this documentation to know how to run this demo.
- Installation
- Define your breadcrumbs
- Choose a template
- Basic Usage
1). To get started with Breadcrumbs, add to your composer.json
file as a dependency:
composer require davejamesmiller/laravel-breadcrumbs
2). Integration in Laravel
Add the service provider to providers:
'providers' => [
// ...
DaveJamesMiller\Breadcrumbs\ServiceProvider::class,
],
And add the facade to aliases:
'aliases' => [
// ...
'Breadcrumbs' => DaveJamesMiller\Breadcrumbs\Facade::class,
],
Create a file called app/Http/breadcrumbs.php
that looks like this:
<?php
// Home
Breadcrumbs::register('home', function($breadcrumbs)
{
$breadcrumbs->push('Home', route('home'));
});
// Home > Blog
Breadcrumbs::register('blog', function($breadcrumbs)
{
$breadcrumbs->parent('home');
$breadcrumbs->push('Blog', route('blog'));
});
By default a Bootstrap-compatible ordered list will be rendered, so if you’re using Bootstrap 3 you can skip this step.
First initialise the config file by running this command:
$ php artisan vendor:publish
Then open config/breadcrumbs.php and edit this line:
'view' => 'breadcrumbs::bootstrap3',
The possible values are:
Bootstrap 3: breadcrumbs::bootstrap3
Bootstrap 2: breadcrumbs::bootstrap2
1). Edit app/HTTP/routes.php
, make sure each of your routes has a name ('as' parameter):
Route::get('home', [
'as' => 'home',
function () {
return view('home');
}
]);
Route::get('blog', [
'as' => 'blog',
function () {
return view('home');
}
]);
2). Add this line to your views:
{!! Breadcrumbs::render('blog'); !!}
3). Then you'll get something like this:
That's it! 🍻 🍻 🍻
You can refer to the documentation to learn more about Laravel Breadcrumbs.
欢迎关注 LaravelTips
, 这是一个专注于为 Laravel 开发者服务, 致力于帮助开发者更好的掌握 Laravel 框架, 提升开发效率的微信公众号.