public static function deleteLaravelRoutes() { $laravelRoutes = \Route::getRoutes(); $dbRoutes = \App\Models\Route::all(); $dbRoutesToDelete = []; $cnt = 0; foreach ($dbRoutes as $dbRoute) { $dbRouteActionName = $dbRoute->action_name; $laravelRoute = null; // Try to find by action $laravelRoute = $laravelRoutes->getByAction($dbRouteActionName); // Try to find by name if (null == $laravelRoute) { $dbRouteName = $dbRoute->name; $laravelRoute = $laravelRoutes->getByName($dbRouteName); } // Laravel route not found, add to list to delete. if (null == $laravelRoute) { $dbRoutesToDelete[] = $dbRoute->id; } } if (($cnt = count($dbRoutesToDelete)) > 0) { \App\Models\Route::destroy($dbRoutesToDelete); } return $cnt; }
/** * 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 = \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; }