Library for managing user's menu.
- Laravel >= 6.0
- Flux Role Permission >= 1.0.2
- Run the command below at the project root to add the package to the Laravel application:
composer require doc88/flux-menu-control
- In the providers list in the config/app.php file add:
'providers' => [
...
Doc88\FluxMenuControl\FluxMenuControlServiceProvider::class,
]
- Run the command below at the root of your project to publish the new provider:
php artisan vendor:publish
- Run migrations
php artisan migrate
- In your User Model add the following lines:
use Doc88\FluxMenuControl\Traits\MenuMount;
class User {
use MenuMount;
}
Class used to Create, Remove, Attach and Dettach Menus and Permission.
- Create a Menu Item
// Create a new Menu Item
Menu::create([
'module' => 'Label of Menu Item', // required
'slug' => 'menu-slug', // required
'icon' => 'menu-item-icon-class' // optional,
'parent' => 'parent-menu-item-slug' // optional
]);
// Return (array):
[
'module' => 'Label of Menu Item',
'slug' => 'menu-slug',
'icon' => null,
'parent_id' => null
]
- Remove a Menu Item
// Remove a Menu Item
Menu::remove('menu-slug');
// Return (bool)
true or false
- Attach a permission to Menu Item
// Attaching list-users permissions to menu-slug menu
Menu::attachPermission('menu-slug', 'list-users');
// Return (bool)
true or false
- Dettach a permission from a Menu Item
// Dettaching list-users permissions to menu-slug menu
Menu::dettachPermission('menu-slug', 'list-users');
// Return (bool)
true or false
- Synchronize Permissions to generate the user's menu
// Synchronizing
Menu::sync($user);
// Return (array)
[
[
"module" => "Label of Menu Item",
"slug" => "menu-slug",
"icon" => null,
],
],
- Get user's menu
// Getting user's menu
Menu::get($user);
// Return (array)
[
[
"module" => "Label of Menu Item",
"slug" => "menu-slug",
"icon" => null,
],
],
It is possible to Get the user's menu using the User class.
- List User's Menu
$user = User::find(1);
// User's Permissions
$user->getMenu();
// Return (array):
[
[
"module" => "Label of Menu Item",
"slug" => "menu-slug",
"icon" => null,
],
],