Laravel-Enterprise-Starter-Kit
Laravel-Enterprise-Starter-Kit copied to clipboard
How to edit breadcrumb ?
Hi, sorry it's me again ;-)
I want to edit the breadcrumb for the different pages I have created, but I don't find the way to do it.
It might be good to add it to the documentation.
BTW, your package is awesome, many thanks.
Hello @dsnoeck,
Glad that you are finding the package helpful, that is why I created it and decided to release it open-source.
Yeah I have to work on the documentation! That giant readme is not great even when it has all the information.
At the moment the crumb trail is kinda static and automatically generated based on how the menu structure is defined and the current page viewed.
It's best explained with an example:
Given this partial menu:
MENU GRAPH | NODE NAME | URL
----------------------------------------------------
\ root /
|- Admin admin.container
| - Users admin.users /admin/users
\ - Roles admin.roles /admin/roles
The bread crumb rendering is called in /resources/themes/default/partials/_body_content.blade.php
with:
{!! MenuBuilder::renderBreadcrumbTrail(null, 'root', false) !!}
The method signature is:
MenuHandlerTrait::renderBreadcrumbTrail( $leaf = null, $topNode = 'root', $includeTopNode = false )
So for all pages using the default theme, the leaf will be null
or unspecified, the root will be root
and the root node will not be rendered.
The root is the left most part of the trail and the leaf the right most part, so if a user clicks on the Roles link, one would expect the crumb trail to look as such: ```Admin > Role".
How does the system figures out the leaf when a null is passed? From the current request URL, it tries to find a match in the Menu definition.
This works for all items that are defined in the menu but, when the user clicks on the link to edit a role the URL no longer matches anything in the menu. So it's also possible to overwrite the leaf node with a session variable, that way in the Role controller one can set:
session(['crumbtrail.leaf' => 'admin.roles']);
And every pages/views generated as a result of this controller will have the crumb trail "Admin > Role" otherwise if the leaf is not defined or deduced, the crumb trail is blank.
So currently the crumb trail is limited to rendering items that are defined in the menu only. There is no way to have a crumb trail like this "Admin > Role > Accountants > Edit", but in the future I want to allow this kind of functionality, I just have not had the time just yet.
I hope that this clarifies the crumb trail and menu system for you a little. Let me know if you have another questions.
Ciao. /s
Hello @sroutier,
Thank you very much for the detailed response. Unfortunately, I needed a breadcrumb with more details. So, if I find the time to do it, I will submit a pull request.
I leave up to you to close or not this issue.
Cheers, Damien
Would love to have a good PR to make the breadcrumb more flexible and useful. Ciao. /S