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_path_is('post') }} ">Post</li>
<li class="sidebar {{ active_path_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?
- Quickstart
- Installation
- Upgrade from v2.x to v3.x
- Usage
- Blade directives
- Additional features
- Cheatsheet
composer require arcesilas/active-state:^4.0
Version 4 is currently in alpha version. If your configuration requires higher than alpha, make sure to specify the full version:
composer require arcesilas/active-state:^4.0.0-alpha
If you want the latest release:
composer require arcesilas/active-state:@dev-develop-v4
Check current path is foo/bar
:
<li class="menu-item {{ Active::ifPathIs('foo/bar') }}">Foo: Bar</li>
will render:
<li class="menu-item active">Foo: Bar</li>
if the current path 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::ifUrlContains(['slug' => $category->slug])}}" href="{{ route('videos.category', $category->slug) }}">