示例#1
0
 /**
  * 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;
 }