/** * Run the database seeds. * * @return void */ public function run() { Model::unguard(); $seeds = [['uri' => 'about', 'controller' => 'ContentsController', 'method' => 'show', 'params' => serialize(['id' => 1])], ['uri' => 'about-us', 'controller' => 'ContentsController', 'method' => 'redirect', 'params' => serialize(['to' => '/about'])]]; foreach ($seeds as $seed) { Route::create($seed); } Model::reguard(); }
/** * Define the routes for the application. * * @param \Illuminate\Routing\Router $router * @return void */ public function map(Router $router) { $router->group(['namespace' => $this->namespace], function (Router $router) { require app_path('Http/routes.php'); if ($this->app->runningInConsole()) { return; } $request = $this->app->request; $uri = substr($request->getRequestUri(), 1); $dbRoute = Route::where('uri', '=', $uri)->first(); if (!$dbRoute) { return; } $params = !empty($dbRoute->params) ? unserialize($dbRoute->params) : []; /* @var \Illuminate\Routing\Route $route */ $router->get($uri, function () use($dbRoute, $params) { $controller = $this->app->make($this->namespace . '\\' . $dbRoute->controller); return call_user_func_array([$controller, $dbRoute->method], $params); }); }); }