pyaesone17 / active-state by pyaesone17

Active State Checker For Laravel Url
Package Data
Maintainer Username: pyaesone17
Maintainer Contact: (Pyae Sone Nyein)
Package Create Date: 2016-01-13
Package Last Update: 2022-02-01
Language: PHP
License: MIT
Last Refreshed: 2024-07-21 03:03:18
Package Statistics
Total Downloads: 50,740
Monthly Downloads: 471
Daily Downloads: 9
Total Stars: 46
Total Watchers: 3
Total Forks: 8
Total Open Issues: 4

Active State

Total Downloads License Latest Stable Version Monthly Downloads

Simple Laravel Active Checker For Request Url

Sometimes you want to check the request url is active or not For the following purpose. Especially for backend sidebar.

Bilby Stampede

Basically we do like this.

<li class="sidebar {{ Request::is('post') ? 'active' : 'no' }} ">Post</li>
<li class="sidebar {{ Request::is('page') ? 'active' : 'no' }} ">Page</li>

It would be nice if we can make shorter. right ?

<li class="sidebar {{ active_check('post') }} ">Post</li>
<li class="sidebar {{ active_check('page') }} ">Page</li>


Install with composer:

Laravel 5.4 and above

composer require pyaesone17/active-state:^1.1.1

Laravel 5.3 and below

composer require pyaesone17/active-state:^0.0.2

And add the service provider in config/app.php

'providers' => [

If you want to use the facade, add this to your facades in config/app.php

'aliases' => [
    'Active' => Pyaesone17\ActiveState\ActiveFacade::class,

To publish configuration file

php artisan vendor:publish --provider="Pyaesone17\ActiveState\ActiveStateServiceProvider"


It will check against whether your request is If the request match this url . It will return the default value from config file. The default value for true state is "active" and false is "no". You can configure on active.php .

{{ Active::check('data') }} 

To check the exact url.

{{ Active::check('data') }} // check request is

To check the url deeply , just pass the true value as second parameter.

{{ Active::check('data',true) }}  // check request is ||*


{{ Active::check(['data','post','categories']) }}  // check request is || ||
{{ Active::check(['data','post','categories'],true) }} // check request is* || // check request is* ||*

To change the return value in runtime, just pass the the third and fourth parameter.

{{ Active::check('data',true,'truth','fake') }} // it will override the value from config file.

Or you can even use helper function.

{{ active_check('data') }}

You can also use this package for conditional displaying data. In some case, You need to render some part of template depends on request.

    <p>Bar and Bazz</p>

Advance Usage and Above version 1.1.1

To check the route name is.

{{ Active::checkRoute('users.index') }} // check request url route name is "users.index"


{{ Active::checkRoute(['users.index','', 'users.edit']) }} // check request url route name is "users.index" or "" or "users.edit"

Sometimes passing multiple routename as parameters is cubersome. You can simple do like this

{{ Active::checkRoute('users.*') }} 

Ofcousre you may change the return value in runtime as second and third params.

{{ Active::checkRoute('users.index','routeIsActive','routeNotActive') }} 


{{ Active::checkRoute(['users.index',''],'routeIsActive','routeNotActive') }} 

For helper function.

{{ active_route('users.comments.*') }} 

Yes it is also avaialable in blade.

    <p>Bar and Bazz</p>

To check the url with the exact same query paramter value.

{{ Active::checkQuery('users?gender=male') }} // check request is


{{ Active::checkQuery(['users?gender=male','users?status=married']) }} // check request is or

Ofcousre you may change the return value in runtime as second and third params.

{{ Active::checkQuery(['users?gender=male','itIsMale','Ah it is wonder woman') }} 


{{ Active::checkQuery(['users?gender=male','users?status=married'],'male or married','nothing') }} 

For helper function.

{{ active_query('users?gender=male') }} 

Yes it is also avaialable in blade.

    <p>Bar and Bazz</p>


Everytime u update package, you have to run "php artisan view:clear" for blade directives.


You can configure the return value of active state.

return [

    // The default  value if the request match given action
    'active_state'      =>  'active',

    // The default  value if the request match given action
    'inactive_state'    =>  'no'