/** * Load the Laravel routes into the application routes for * permission assignment. * * @return int The number of Laravel routes loaded. */ public static function loadLaravelRoutes() { $AppRoutes = \Route::getRoutes(); $cnt = 0; foreach ($AppRoutes as $appRoute) { $name = $appRoute->getName(); $methods = $appRoute->getMethods(); $path = $appRoute->getPath(); $actionName = $appRoute->getActionName(); if (!str_contains($actionName, 'AuthController') && !str_contains($actionName, 'PasswordController')) { foreach ($methods as $method) { $route = null; if ('HEAD' !== $method && !starts_with($path, '_debugbar')) { // Skip all DebugBar routes. // TODO: Use Repository 'findWhere' when its fixed!! // $route = $this->route->findWhere([ // 'method' => $method, // 'action_name' => $actionName, // ])->first(); $route = \Etherbase\App\Models\Route::ofMethod($method)->ofActionName($actionName)->ofPath($path)->first(); if (!isset($route)) { $cnt++; $newRoute = Route::create(['name' => $name, 'method' => $method, 'path' => $path, 'action_name' => $actionName, 'enabled' => 1]); } } } } } return $cnt; }
/** * * * @param array $attributes * @param $user */ public function assignRoutes(array $attributes = []) { if (array_key_exists('routes', $attributes) && is_array($attributes['routes']) && "" != $attributes['routes'][0]) { $this->clearRouteAssociation(); foreach ($attributes['routes'] as $id) { $route = \Etherbase\App\Models\Route::find($id); $this->routes()->save($route); } } else { $this->clearRouteAssociation(); } }
/** * @return \Illuminate\View\View */ public function load() { Audit::log(Auth::user()->id, trans('admin/routes/general.audit-log.category'), trans('admin/routes/general.audit-log.msg-load')); $nbRoutesLoaded = \Etherbase\App\Models\Route::loadLaravelRoutes(); Flash::success(trans('admin/routes/general.status.loaded', ['number' => $nbRoutesLoaded])); return redirect('/admin/routes'); }