While creating an admin menu, i was wondering how to set active class item. The menu item have to stay active if the controller is showing, editing or doing something else.
sidebar.blade.php
<li class="nav-item">
<a class="nav-link {{ (Route::current()->getName() == 'posts' ? 'active' : '') }}" href="/admin/posts">Posts</a>
</li>
routes/web.php
// POSTS
Route::resource('/admin/posts', 'Admin\PostController');
How to set a shared name for all resources (index, create, show, etc.)?
I was hoping to do something like this but...
Route::resource('/admin/posts', 'Admin\PostController')->name('posts');
Thanks
@if(Route::is('posts')) active @endif
as shorthand for your check above. It also supports wildcards:@if(Route::is('admin.*')) active @endif
, which will match all routes starting with anadmin.
prefix. – Namoshek Apr 14 '18 at 10:56