<?php
 namespace VnChocola\Module\Master;
 use TCMS\Module;
 use Route;
 use Model;
 use LayoutData;
 class MasterBranchs extends Module {
 protected function initialize() {
 }
 protected function registerRoutes() {
 Route::get('/branchs', 'IndexController', 'index')->name('index');
 Route::get('/branchs/create', 'IndexController', 'create')->name('create');
 Route::post('/branchs/create', 'IndexController', 'postCreate')->name('postCreate');
 Route::get('/branchs/update/{id}', 'IndexController', 'update')->name('update');
 Route::post('/branchs/update/{id}', 'IndexController', 'postUpdate')->name('update');
 Route::post('/branchs/delete', 'IndexController', 'postDelete')->name('delete');
 }
 public function registerComponent() {
 Model::add('BranchsModel',\VnChocola\Model\BranchsModel::class,true);
 Model::add('StoresModel',\VnChocola\Model\StoresModel::class,true);
 }
 public function boot() {
 LayoutData::addMenuItem('branchs', route('index'), lang('branch_model.name'), 'primary', function(\LayoutMenuItem $menuItem) {
 $menuItem->icon = 'fas fa-map-marked';
 $menuItem->middleware = function($auth) {
 return $auth->hasRole(\RoleGlobal::$role->viewAllBranch);
 }
;
 }
);
 }
 public function middleware(string $routeName, $auth) {
 switch($routeName) {
 case 'index': return $auth->hasRole(\RoleGlobal::$role->viewDrinks);
 case 'create': case 'postCreate': return $auth->hasRole(\RoleGlobal::$role->createBranch);
 case 'update': return $auth->hasRole(\RoleGlobal::$role->updateBranch);
 case 'delete': return $auth->hasRole(\RoleGlobal::$role->deleteBranch);
 default: return false;
 }
 }
 }
