PHPackages                             erickcomp/laravel-breadcrumbs-attributes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. erickcomp/laravel-breadcrumbs-attributes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

erickcomp/laravel-breadcrumbs-attributes
========================================

Provides breadcrumbs to controller methods using PHP Attributes

3.0.1(11mo ago)1281MITPHPPHP ^8.1

Since Jul 24Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/erickcomp/laravel-breadcrumbs-attributes)[ Packagist](https://packagist.org/packages/erickcomp/laravel-breadcrumbs-attributes)[ Docs](https://github.com/erickcomp/laravel-breadcrumbs-attributes)[ RSS](/packages/erickcomp-laravel-breadcrumbs-attributes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (19)Used By (0)

 [![Latest Stable Version](https://camo.githubusercontent.com/b80205541df143eed87bae28490dd4b7c04cf00a8c1161c4d4c7440169bafba5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f657269636b636f6d702f6c61726176656c2d62726561646372756d62732d61747472696275746573)](https://packagist.org/packages/erickcomp/laravel-breadcrumbs-attributes) [![Total Downloads](https://camo.githubusercontent.com/201c8f6bb3b294d8c24702b26d6fb4c84c0aae14fb3a15388bbc68f8105b8c5b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f657269636b636f6d702f6c61726176656c2d62726561646372756d62732d61747472696275746573)](https://packagist.org/packages/erickcomp/laravel-breadcrumbs-attributes) [![License](https://camo.githubusercontent.com/21c13276c0f30bd3b4135deec3c1e47fdd0c68f7ee5fa3f30e4e1eb32f0b7af3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f657269636b636f6d702f6c61726176656c2d62726561646372756d62732d61747472696275746573)](https://packagist.org/packages/erickcomp/laravel-breadcrumbs-attributes)

Use PHP 8 attributes to create breadcrumbs for controllers actions in a Laravel app
===================================================================================

[](#use-php-8-attributes-to-create-breadcrumbs-for-controllers-actions-in-a-laravel-app)

This package provides PHP 8 Attribute classes to automatically create breadcrumbs for your controller actions. This package was inspired by Spatie's wonderful [Laravel Routes Attributes](https://github.com/spatie/laravel-route-attributes#use-php-8-attributes-to-register-routes-in-a-laravel-app). In fact, a big portion of the "controller methods discovery" was copied from Laravel Routes Attributes package (Thanks for that, Spatie fellows!).

How it works
------------

[](#how-it-works)

It works by scanning the controllers in the directories that contains your controllers and putting into a "Breadcrumb basket" all the crumbs you put in your controller actions and making it available at your controllers and views through DI or the `\ErickComp\BreadcrumbAttributes\Facades\BreadcrumbsTrail` facade.

Custom controllers directories
------------------------------

[](#custom-controllers-directories)

If, for some, reason, you keep your controllers in a different directory, fear not! All you have to do is publish the config file and write down the directories where your controllers lie.

Collision when defining breadcrumbs
-----------------------------------

[](#collision-when-defining-breadcrumbs)

If you define breadcrumbs for the same route twice, and exception will be thrown. This behavior can be changed through the config `erickcomp-laravel-breadcrumbs-attributes.when_already_defined`. This config accepts one of these values:

- `throw`: It's the default behavior. An exception will be thrown when the breadcrumbs scanner finds the second definition of the breadcrumb;
- `ignore`: The **first** definition of the breadcrumb will be used and the following ones will be **silently ignored**. It's useful to prevent a definition from a base controller class to be overriden by children controller classes.
- `override`: The **last** definition of the breadcrumb will be used and the previous ones following will be **silently ignored**. It's useful to create a fallback breadcrumb definition on a base controller class while allowing it to be overriden into a child controller class.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require erickcomp/laravel-breadcrumbs-attributes
```

You can publish the config file with:

```
php artisan vendor:publish --provider="ErickComp\BreadcrumbAttributes\Providers\RouteAttributesServiceProvider" --tag="config"
```

This is the contents of the published config file:

```
