Forked from phillipsharring/RouteServiceProvider.php
Created
December 25, 2017 06:38
-
-
Save kevin50406418/355e37805139d7b812f59923c41d8a8c to your computer and use it in GitHub Desktop.
Revisions
-
phillipsharring revised this gist
Oct 6, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,7 @@ an arbitrary URI. The your.com/something-else link would go somewhere else and do something different. Use it for pretty URLs, your CMS, short links, you name it. Use your imagination. It's not perfect. I haven't figured out if/how route model binding works here. I don't think it can, honestly, so your controllers would have to act accordingly. Alternatively, you could -
phillipsharring revised this gist
Oct 6, 2015 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ Make a migration to add the routes table to your database. Use the Schema::create statement in create_routes_table.php Values will be like so: @@ -10,12 +11,17 @@ Values will be like so: | 3 | something-else | ArbitraryController@redirect | "a:1:{s:3:""foo"";s:3:""bar"";}" | +----+----------------+------------------------------+-----------------------------------+ Now, your.com/about will show the about page. Presumably PagesController@show will pull the content from a database using a Page model. And your.com/about-us will redirect. PagesController@redirect would simply redirect to an arbitrary URI. The your.com/something-else link would go somewhere else and do something different. Use it for pretty URLs, shor links, you name it. Use your imagination. It's not perfect. I haven't figured out if/how route model binding works here. I don't think it can, honestly, so your controllers would have to act accordingly. Alternatively, you could flesh out the map function with some logic to do the bindings there. Finally, I'm not sure if this is a good place to put it. Suggestions/improvements welcome. I'm learning; It's something. -
phillipsharring revised this gist
Oct 6, 2015 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ Make a migration to add the routes table to your database. Use the Schema::create statement in create_routes_table.php Values will be like so: +----+----------------+------------------------------+-----------------------------------+ | id | uri | action | params | +----+----------------+------------------------------+-----------------------------------+ | 1 | about | PagesController@show | "a:1:{s:5:""pages"";i:1;}" | | 2 | about-us | PagesController@redirect | "a:1:{s:2:""to"";s:5:""about"";}" | | 3 | something-else | ArbitraryController@redirect | "a:1:{s:3:""foo"";s:3:""bar"";}" | +----+----------------+------------------------------+-----------------------------------+ Now, your.com/about will show the about page. Presumably PagesController@show will pull the content from a database using a Page model. And your.com/about-us will redirect. PagesController@redirect would simply redirect to an arbitrary URI. The your.com/something-else link would go somewhere else and do something different. Use it for pretty URLs, shor links, you name it. Use your imagination. It's not perfect. I haven't figured out if/how route model binding works here. I don't think it can, honestly, so your controllers would have to act accordingly. Alternatively, you could flesh out the map function with some logic to do the bindings there. Finally, I'm not sure if this is a good place to put it. Suggestions/improvements welcome. I'm learning; It's something. -
phillipsharring revised this gist
Oct 6, 2015 . No changes.There are no files selected for viewing
-
phillipsharring revised this gist
Oct 6, 2015 . No changes.There are no files selected for viewing
-
phillipsharring revised this gist
Oct 6, 2015 . 2 changed files with 14 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ <?php // ... /** * Define the routes for the application. * @@ -14,7 +18,6 @@ public function map(Router $router) $dbRoute = Route::where('uri', '=', $uri)->first(); if ($dbRoute) { $router->get($uri, function() use ($dbRoute) { $segments = explode('@', $dbRoute->action); $controller = $segments[0]; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ <?php // ... Schema::create('routes', function (Blueprint $table) { $table->increments('id'); $table->string('uri'); $table->string('action'); $table->string('params'); }); -
phillipsharring created this gist
Oct 6, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ /** * 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) { require app_path('Http/routes.php'); if (!$this->app->runningInConsole()) { $uri = substr($this->app->request->getRequestUri(), 1); $dbRoute = Route::where('uri', '=', $uri)->first(); if ($dbRoute) { /* @var \Illuminate\Routing\Route $route */ $router->get($uri, function() use ($dbRoute) { $segments = explode('@', $dbRoute->action); $controller = $segments[0]; $method = $segments[1]; $obj = $this->app->make($this->namespace . '\\' . $controller); $params = (!empty($dbRoute->params)) ? unserialize($dbRoute->params) : []; return call_user_func_array([$obj, $method], $params); }); } } }); }