This package helps you check if a given link matches the current URL, route or query string. This is especially useful in sidebars.
History
This package was originally a fork from pyaesone17/active-state. To fix issue #8, I rewrote entirely the package.
Basically you would do like this:
<li class="sidebar {{ Request::is('post') ? 'active' : 'no' }} ">Post</li>
<li class="sidebar {{ Request::is('page') ? 'active' : 'no' }} ">Page</li>
With this package, you can make it shorter:
<li class="sidebar {{ active_url_is('post') }} ">Post</li>
<li class="sidebar {{ active_url_is('page') }} ">Page</li>
Or, if you prefer to check the route:
<li class="sidebar {{ active_route_in('users.list') }}">Users list</li>
<li class="sidebar {{ active_route_in('groups.list') }}">Groups list</li>
Keywords: route, url, query, menu, link, request, laravel, active
Maybe you just need the cheatsheet?
composer require arcesilas/active-state:^2.0
Check current URL is foo/bar
:
<li class="menu-item {{ Active::ifUrlIs('foo/bar') }}">Foo: Bar</li>
will render:
<li class="menu-item active">Foo: Bar</li>
if the current URL is actually foo/bar
.
Check route name is posts
:
<a class="nav-link {{ Active::ifRouteIn('posts') }}" href="{{ route('posts') }}">
Check route name is posts
and slug
parameter is a given value:
<a class="nav-link {{Active::ifRouteIs('posts.category', ['slug' => $category->slug])}}" href="{{ route('posts.category', $category->slug) }}">
Check query string contains argument foo
with value bar
:
<a class="nav-link {{Active::ifQueryHas('videos.category', ['slug' => $category->slug])}}" href="{{ route('videos.category', $category->slug) }}">