<?php
 namespace VnChocola\Module\Master;
 use TCMS\Module;
 use Route;
 use Model;
 use LayoutData;
 class MasterCarcompartments extends Module {
 protected function initialize() {
 }
 protected function registerRoutes() {
 Route::get('/car-compartments', 'IndexController', 'index')->name('index');
 Route::get('/car-compartments/create', 'IndexController', 'create')->name('create');
 Route::post('/car-compartments/create', 'IndexController', 'postCreate')->name('postCreate');
 Route::get('/car-compartments/update/{id}', 'IndexController', 'update')->name('update');
 Route::post('/car-compartments/update/{id}', 'IndexController', 'postUpdate')->name('postUpdate');
 Route::post('/car-compartments/delete', 'IndexController', 'postDelete')->name('delete');
 }
 public function registerComponent() {
 Model::add('CarCompartmentsModel', \VnChocola\Model\CarCompartmentsModel::class, true);
 Model::add('CarCompartmentGroupModel', \VnChocola\Model\CarCompartmentGroupModel::class, true);
 }
 public function boot() {
 LayoutData::addMenuItem('carcompartments', route('index'), lang('CarCompartment_model.name'), 'primary', function(\LayoutMenuItem $menuItem) {
 $menuItem->icon = 'fas fa-car';
 $menuItem->middleware = function($auth) {
 return $auth->hasRole(\RoleGlobal::$role->viewCarCompartment);
 }
;
 }
);
 }
 public function middleware(string $routeName, $auth) {
 switch($routeName) {
 case 'index': return $auth->hasRole(\RoleGlobal::$role->viewCarCompartment);
 case 'create': case 'postCreate': return $auth->hasRole(\RoleGlobal::$role->createCarCompartment);
 case 'update': case 'postUpdate': return $auth->hasRole(\RoleGlobal::$role->updateCarCompartment);
 case 'delete': return $auth->hasRole(\RoleGlobal::$role->deleteCarCompartment);
 default: return false;
 break;
 }
 }
 }
