web-id / breadcrumb
Make breadcrumbs using a route macro
Requires
- php: ^8.3|^8.4
- illuminate/contracts: ^12.0|^13.0
- inertiajs/inertia-laravel: ^2.0|^3.0
- spatie/laravel-navigation: ^1.3
- spatie/laravel-package-tools: ^1.92
- webmozart/assert: ^2.1
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.2
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^12.0
- dev-main
- 3.0.1
- 3.0.0
- 2.1.0
- 2.0.0
- v1.2.4.x-dev
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-update-php-dependencies
- dev-dependencies-update
- dev-inertia-v2
- dev-add-validation-and-tests
- dev-php8.2
- dev-laravel_10
- dev-dependabot/github_actions/aglipanci/laravel-pint-action-2.2.0
- dev-dependabot/github_actions/ramsey/composer-install-2
- dev-bugfix_inertia_config
- dev-issue1/add-ide-helper
- dev-add-blade-support
This package is auto-updated.
Last update: 2026-03-30 12:01:10 UTC
README
Installation
Requires PHP 8.3+, Laravel 12 or 13, and inertiajs/inertia-laravel 2.x or 3.x when using the Inertia frontend option. (This package does not support PHP 8.2, even though Laravel 12 allows it upstream.)
You can install the package via composer:
composer require web-id/breadcrumb
Publish config file
php artisan vendor:publish --provider="WebId\Breadcrumb\BreadcrumbServiceProvider" --tag="config"
Usage
This package uses Spatie's Laravel Navigation package (https://github.com/spatie/laravel-navigation).
Frontend
If you are using Inertia, update the frontend key to the config file to inertia.
'frontend' => 'inertia',
If your project uses Blade templates, set the config to blade.
'frontend' => 'blade',
Breadcrumb root element
Edit the breadcrumb_root title and route name in your published breadcrumb.php config file.
For instance, if your root element is your homepage:
'breadcrumb_root' => [ 'title' => 'Homepage', 'route_name' => 'homepage', ],
Note
Your route must be named.
Breadcrumb class
To create a new breadcrumb, create a class that extends the WebId\Breadcrumb\Breadcrumb class.
In this example, we will create a breadcrumb for the blog page (list of all articles):
use WebId\Breadcrumb\Breadcrumb; class BlogBreadcrumb extends Breadcrumb { public function index(): array { return $this->render( $this->baseBreadcrumb() ->add('Blog') ->tree() ); } }
Notice that the add() method only takes a name (blog). Indeed, the last element of a breadcrumb being
the active page, you don't need to attach a link to it.
In this example, your view should have a breadcrumb key with this data:
[
{
"url": "https://www.yourwebsite.com",
"title": "Homepage"
},
{
"title": "Blog"
}
]
If you want to create the breadcrumb for a single blog post, you probably want the parent element to be the blog page. In that case, add a method as follow:
public function show(Post $post): array { return $this->render( $this->baseBreadcrumb() ->add('Blog', route('blog.index')) ->add($post->title, route('blog.show', ['post' => $post])) ->tree() ); }
Notice that your can Typehint a model in your breadcrumb methods as if you were in a controller method.
In this example, your view should have a breadcrumb key with this data:
[
{
"url": "https://www.yourwebsite.com",
"title": "Homepage"
},
{
"url": "https://www.yourwebsite.com/blog",
"title": "Blog"
},
{
"title": "Article title"
}
]
Register a breadcrumb to a route
In order for your breadcrumb to be accessible in your Inertia view, you have to register it to the associated route as follow:
Route::get('/blog', [BlogController::class, 'index'])->breadcrumb([BlogBreadcrumb:class, 'index']); Route::get('/blog/{post}', [BlogController::class, 'show'])->breadcrumb([BlogBreadcrumb:class, 'show']);
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.