Helper class for Laravel applications to get active class base on current route name.
Install using composer
composer require rukhsar/laravel-active-route
Add below line to your service providers array in config/app.php
Rukhsar\ActiveRoute\ActiveRouteServiceProvider::class,
Add below line to your aliases array in config/app.php
'Active' => Rukhsar\ActiveRoute\Facades\Active::class,
Publish config file using
php artisan vendor:publish --provider="Rukhsar\ActiveRoute\ActiveRouteServiceProvider" --tag="config"
In config/activeroute.php
you can modify the css active class which notmally active
if you are using bootsrap.
return [
// The default css class value if the request match given route name
'class' => 'active',
];
You can use this package in different ways like...
Active::route('route.name'); // Facade example
app('active')->route('route.name'); // Application container example
active_route('route.name'); // Helper function
// Wildcard exmaples
Active::route('route.name.*');
active_route('route.name.*');
// Multiple Routes
Active::route(['route.name1.*', 'route.name2.*']);
active_route(['route.name1.*', 'route.name2.*']);
You can also use custom blade directive in your blade templates.
@ifActiveRoute('route.name')
<p>True</p>
@else
<p>False</p>
@endif
<li class="item {{ active_route('admin.index') }}">
<a href="admin/index">Dashboard</a>
</li>
This project is open-sourced software licensed under the MIT License.