Nasrul Hazim Bin Mohamad

Laravel: CRUD Breadcrumb

Jul
10

Assalamualaikum & Hi,

Today, I just want to share a little tip on managing your breadcrumb when using Laravel Breadcrumbs.

It is common to have following breadcrumb setup:


Main Menu > Module
Main Menu > Module > Create
Main Menu > Module > Edit
Main Menu > Module > Details

And it is kind of messy if you have lots of module to setup the breadcrumbs.

So, I do some digging on Laravel Breadcrumbs codes and found out the main BreadcrubManager class do have use Macroable trait!.

So the solution for the above use case is to extend the functionality of the breadcrumb using macro! Yeah!

Keep it short, grab the following codes, and call it in your service provider \App\Macros\Routing\Breadcrumb::registerMacros() (my favourite approach in registering macros!)

The usage will be like the following:

Now you can attach a lot more breadcrumbs!

Bonus

Add the following code snippet at the end of your routes/breadcrumbs.php to include multiple breadcrumb files in routes/breadcrumbs/ directory – of course you need to create the directory first.

Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *

9 − six =