Laravel Breadcrumbs Package

Packages

June 15th, 2018

breadcrumbs-package.jpg

Breadcrumbs are one of those things that I don’t think about until I need them, and then I feel like I recreate a system for them in my application every time.

Laravel Breadcrumbs is a package by Dave James Miller that makes adding breadcrumb navigation to your application (relatively) painless with a simple API:

1// Home
2Breadcrumbs::for('home', function ($trail) {
3 $trail->push('Home', route('home'));
4});
5
6// Home > About
7Breadcrumbs::for('about', function ($trail) {
8 $trail->parent('home');
9 $trail->push('About', route('about'));
10});
11
12// Home > Blog
13Breadcrumbs::for('blog', function ($trail) {
14 $trail->parent('home');
15 $trail->push('Blog', route('blog'));
16});

To render breadcrumbs, you can pick from the following templates that ship with the Laravel Breadcrumb package at the time of writing:

  • breadcrumbs::bootstrap4
  • breadcrumbs::bootstrap3
  • breadcrumbs::bootstrap2
  • breadcrumbs::bulma
  • breadcrumbs::foundation6
  • breadcrumbs::materialize
  • breadcrumbs::json-ld
  • The path to a custom view: e.g. partials.breadcrumbs

Depending on which template you need, you configure it as a published configuration in config/breadcrumbs.php:

1'view' => 'breadcrumbs::bootstrap4',

And finally you render the breadcrumbs in your view:

1{{ Breadcrumbs::render('category', $category) }}

This package even supports JSON-LD structured data for SEO purposes which is really helpful:

1<head>
2 ...
3 {{ Breadcrumbs::view('breadcrumbs::json-ld', 'category', $category) }}
4 ...
5</head>

Learn More

The Laravel Breadcrumb package is highly customizable and has a lot of documented options in the readme. You should check out the official GitHub repository for complete documentation and installation instructions.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.