irsyadulibad/laravel-activehelper

Active State Helper for Laravel Blade
1,207 5
Install
composer require irsyadulibad/laravel-activehelper
Latest Version:0.0.1
License:MIT
Last Updated:Feb 1, 2024
Links: GitHub  ·  Packagist
Maintainer: irsyadulibad

laravel-activehelper

Active State Helper for Laravel Blade

Lightweight and simple

GitHub GitHub repo size Hits

Introduction

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('post')">Post</li>
<li class="sidebar @active('page.index')">Page</li>

Installation

Installation is best done via composer:

composer require irsyadulibad/laravel-activehelper

Add the service provider in config/app.php

'providers' => [
  .....,
  Irsyadulibad\LaravelActivehelper\ActiveHelperServiceProvider::class,
]

Usage

It will check the name of the currently active route. If match, it will return active string

<li class="sidebar @active('post')">Post</li>

Nested State

You can also do it on nested navbar items,in some case you need to grouping the item by category or model name

<li class="nav-item @active('user')">
  <a href="#">User</a>
  <ul>
    <li class="nav-link @active('user.index')">
      <a href="#">List Users</a>
    </li>
    <li class="nav-link @active('user.create')">
      <a href="#">Add User</a>
    </li>
</li>

More States

To check for more than one match states, you can add comma to the parameter

@active('user.index,post.create')

Author's Profile:

Github: [https://github.com/irsyadulibad]
Website: [http://irsyadulibad.my.id]
Facebook: [https://facebook.com/irsyadulibad.dev]

Related Packages

spatie/laravel-blade-javascript

A Blade directive to export variables to JavaScript

966,893 619
philo/laravel-blade

Use the simple and yet powerful Laravel Blade templating engine as a standalone...

687,522 354
igaster/laravel-theme

Laravel Themes: Asset & Views folder per theme. Theme inheritance. Blade integra...

1,279,271 515
jeroennoten/laravel-adminlte

Easy AdminLTE v4 integration with Laravel

5,332,381 4,000
fitztrev/laravel-html-minify

Minifies the HTML output of Laravel 4 applications

216,611 413