cocomelon/laravel-active-state
最新稳定版本:v1.0.1
Composer 安装命令:
composer require cocomelon/laravel-active-state
包简介
A Laravel package to manage active states easily
README 文档
README
A simple Laravel package to manage active CSS classes in Blade templates based on current route.
Features
- Easily add an "active" class to menu items or links in Blade.
- Configurable active CSS class name.
- Supports route pattern matching.
Installation
You can install the package via Composer:
composer require cocomelon/laravel-active-state
Optionally, publish the config file to customize the active class name:
php artisan vendor:publish --tag=config
This will create a config file at config/activestate.php.
Configuration
The config file contains:
return [
/*
|--------------------------------------------------------------------------
| CSS class for active state
|--------------------------------------------------------------------------
|
| This class will be output by the @active Blade directive when
| the current route matches the given pattern.
|
*/
'active_class' => 'active',
];
Change 'active' to whatever CSS class you want.
Usage
Use the Blade directive @active in your views to add the active class based on current route name.
Example:
<li class="@active('home')">Home</li>
<li class="@active('posts.*')">Posts</li>
This will output active (or your configured class) if the current route matches.
How it works
Behind the scenes, @active('route.name') translates to:
<?php echo request()->routeIs('route.name') ? config('activestate.active_class') : ''; ?>
License
The MIT License (MIT). Please see License File for more information.
Made with ❤️ by Cocomelon
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-02