Skip to content

Helper class for Laravel applications to get active class base on current route name.

Notifications You must be signed in to change notification settings

Rukhsar/laravel-active-route

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Active Route

v1.0

Helper class for Laravel applications to get active class base on current route name.

Installation

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"

Config File

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',

];

Usage

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

Practical use in application

<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.

About

Helper class for Laravel applications to get active class base on current route name.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages