https://github.com/adelf/laravel-menu
Convenient menu component for Laravel
https://github.com/adelf/laravel-menu
laravel laravel-5-package menu
Last synced: about 1 year ago
JSON representation
Convenient menu component for Laravel
- Host: GitHub
- URL: https://github.com/adelf/laravel-menu
- Owner: adelf
- License: mit
- Created: 2018-07-04T17:00:45.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-08T12:51:40.000Z (over 7 years ago)
- Last Synced: 2025-04-14T02:35:50.051Z (about 1 year ago)
- Topics: laravel, laravel-5-package, menu
- Language: PHP
- Homepage:
- Size: 25.4 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Menu
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE)
[![Scrutinizer][ico-scrutinizer]][link-scrutinizer]
Simple component for creating menus in Laravel. Instead of using controllers or creating huge blade templates suggests only one configuration file.
Example (**resources/menu/default.php**):
```php
'menu.menu', // custom blade template can be provided here
'items' => [
[
'name' => 'Home',
'link' => route('dashboard'),
'active' => activeMenuController(\App\Http\Controllers\DashboardController::class),
'icon' => 'home',
],
[
'name' => 'Users',
'auth' => authMenuCan('manageUsers'), // Will be shown if user "can" 'manageUsers'.
// Gate::check('manageUsers') will be checked
'link' => '/users',
'active' => activeMenuUrlPrefix('users'), // Will be active for all '/users*' URL's
'icon' => 'user',
],
[
'name' => trans('complex.auth'),
'auth' => function (){
return Gate::check('one') || Gate::check('two');
},
'link' => '/complex-auth',
'active' => activeMenuUrlPrefix('complex-auth'),
'icon' => 'complex',
],
[
'name' => 'Group',
'icon' => 'group',
'items' => [
[
'name' => 'Orders',
'link' => '/orders', // route('orders'),
'active' => activeMenuController(\App\Http\Controllers\OrdersController::class),
'icon' => 'orders',
],
[
'name' => 'Bar',
'link' => '/bar', // route('bar'),
'active' => activeMenuController(\App\Http\Controllers\BarController::class),
'icon' => 'bar',
],
],
],
],
];
```
Blade template for one-level menus can be very simple:
```blade
```
For two-level menus it's more complicated. Example of it is provided by package.
## Installation
First, require package via composer:
```
composer require adel/laravel-menu
```
For Laravel < 5.5 check [Laravel < 5.5 installation](#laravel--55-installation) section.
Then publish some initial configuration and blade template:
```
php artisan vendor:publish --provider="Adelf\LaravelMenu\LaravelMenuServiceProvider"
```
**resources/menu/default.php** and **resources/views/menu/menu.blade.php** files will appear. It's just an examples. Provide your own configuration and blade template.
## Using
This will render menu's blade template
```blade
{!! LaravelMenu::render() !!}
```
Title of active item can be used for title:
```blade
{{array_get(LaravelMenu::getLastActiveItem(), 'name', 'Default title')}}
```
## Multiple menus
Another menu can be created by defining it in new file on **resources/menu** directory. For example, **resources/menu/admin.php**
```blade
{!! array_get(LaravelMenu::getLastActiveItem('admin'), 'name', 'Default title') !!}
{!! LaravelMenu::render('admin') !!}
```
## Laravel < 5.5 installation
Service provider and facade should be registered in **config/app.php**:
```php
'providers' => [
...
Adelf\LaravelMenu\LaravelMenuServiceProvider::class,
],
'aliases' => [
...,
'LaravelMenu' => Adelf\LaravelMenu\Facade::class,
],
```
[ico-version]: https://img.shields.io/packagist/v/adel/laravel-menu.svg?style=flat-square
[ico-license]: https://img.shields.io/packagist/l/adel/laravel-menu.svg?style=flat-square
[ico-scrutinizer]: https://scrutinizer-ci.com/g/adelf/laravel-menu/badges/quality-score.png?b=master
[link-packagist]: https://packagist.org/packages/adel/laravel-menu
[link-scrutinizer]: https://scrutinizer-ci.com/g/adelf/laravel-menu/