php - What is the best way to display menu in Laravel 5.1?
I would like to ask that which is the best way to show menu with access parameters.
So, now I'm using the following code in mydefault.blade.php
:
@if (Sentry::getUser()->hasAccess('something'))
<li >
<a href="{{ URL::to('panda/flot_charts') }}" >
<span >Menu 1</span><i ></i>
</a>
<ul >
@if (Sentry::getUser()->hasAccess('school'))
<li active" : '') }}">
<a href="{{ route('school') }}"><i ></i><span >Submenu</span></a>
</li>
@endif
</ul>
</li>
@endif
I know that this solution is not really good. I'm looking for an easier and more simple way to show menu.
I always have to check what page the visitor sees and the same menu has to be active.
Now I'm using Sentry, but I'd like to use middleware in the future.
Shall I store the menu parameters indb
?
Thanks for your help!
Peter
Answer
Solution:
I use
Sentinel
which is the updated version ofSentry
and is also open source. Here's what I use for my authentication middleware:Then your menu code could be changed to:
This is only a slight change, though. You might want to check out Caffeinated Menus which appears to be the most popular of the package for Laravel 5.1 menu creation on Packalyst.