This repository was archived by the owner on Jun 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Menus
Jose Luis Fonseca edited this page Oct 22, 2017
·
6 revisions
Jarvis Platform utiliza un fork del paquete Pingpong Menus que esta mantenido por el equipo de hecho en Laravel https://github.com/hechoenlaravel/jarvis-menus para administrar los menús de la aplicación.
En el módulo de usuarios se puede ver un ejemplo de implementación del menu. Para esto debe crear una clase de definición del menu como esta:
<?php
namespace Modules\Users\Menu;
use Illuminate\Support\Facades\Auth;
/**
* Class MenuDefinition
* @package Modules\Users\Menu
*/
class MenuDefinition
{
/**
* @var \Illuminate\Support\Collection
*/
public $items;
/**
* MenuDefinition constructor.
*/
public function __construct()
{
$this->items = collect();
$this->items->push($this->getList());
$this->items->push($this->getConfiguration());
$this->items->push($this->getRoles());
$this->items->push($this->getProfileFields());
}
/**
* @return string
*/
public function getName()
{
return "Usuarios";
}
/**
* @return string
*/
public function getInstance()
{
return 'sidebar';
}
/**
* @return string
*/
public function isDropdown()
{
return true;
}
/**
* @return array
*/
public function getList()
{
return [
'route' => 'users.index',
'type' => 'route',
'name' => 'Listar',
'active-state' => function() {
$request = app('Illuminate\Http\Request');
return $request->is('users*');
},
'ability' => function() {
return !Auth::user()->hasPermissionTo('Listar usuarios');
}
];
}
/**
* @return array
*/
public function getConfiguration()
{
return [
'name' => 'CONFIGURACION',
'type' => 'header',
];
}
/**
* @return array
*/
public function getRoles()
{
return [
'route' => 'roles.index',
'type' => 'route',
'name' => 'Roles',
'active-state' => function() {
$request = app('Illuminate\Http\Request');
return $request->is('roles*');
},
'ability' => function() {
return !Auth::user()->hasPermissionTo('Listar roles');
}
];
}
/**
* @return array
*/
public function getProfileFields()
{
return [
'route' => 'users.config',
'type' => 'route',
'name' => 'Campos de perfil',
'active-state' => function() {
$request = app('Illuminate\Http\Request');
return $request->is('config/users*');
},
'ability' => function() {
return !Auth::user()->hasPermissionTo('Editar campos de perfil');
}
];
}
}Luego puede crear un MenuServiceProvider y agregar la definición:
<?php
namespace Modules\Users\Providers;
use Modules\Users\Menu\MenuDefinition;
use Illuminate\Support\ServiceProvider;
class MenuServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Boot the application events.
*
* @return void
*/
public function boot()
{
$menuService = app('menu.service');
$menuService->addMenuDefinition(MenuDefinition::class);
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
}
}