rukhsar/laravel-active-route

A laravel helper package.

v1.4 2018-03-03 00:12 UTC

This package is not auto-updated.

Last update: 2024-12-07 21:17:22 UTC


README

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.