Created
October 27, 2015 15:30
-
-
Save kevinruscoe/28a9e707d32a17eab16f to your computer and use it in GitHub Desktop.
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 characters
<?php | |
return [ | |
'routes' => [ | |
'post' => [ | |
'route' => '/post/{blog}', | |
'identifier' => 'slug' | |
], | |
'page' => [ | |
'route' => '/{page}', | |
'identifier' => 'slug' | |
] | |
] | |
] | |
?> |
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 characters
<?php | |
namespace App; | |
use Router; | |
use Route; | |
class ConfigRouteBinder { | |
function bind(){ | |
$this->registerRoutes(); | |
} | |
private function queryContent($type, $identifier_type, $identifier_value){ | |
$content = Content::whereType($type)->where($identifier_type, $identifier_value)->first(); | |
if( !$content ){ | |
abort(404); | |
} | |
return $content; | |
} | |
private function registerRoutes(){ | |
foreach( config('cms.routes') as $route => $meta ){ | |
Route::get($meta['route'], function($identifier) use ($route, $meta){ | |
$content = $this->queryContent($route, $meta['identifier'], $identifier); | |
return (new \App\Http\Controllers\ContentController)->show($content); | |
}); | |
Route::post($meta['route'], function($identifier) use ($route, $meta){ | |
$content = $this->queryContent($route, $meta['identifier'], $identifier); | |
return (new \App\Http\Controllers\ContentController)->show($content); | |
}); | |
} | |
} | |
} | |
?> |
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 characters
<?php | |
/* | |
|-------------------------------------------------------------------------- | |
| Application Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register all of the routes for an application. | |
| It's a breeze. Simply tell Laravel the URIs it should respond to | |
| and give it the controller to call when that URI is requested. | |
| | |
*/ | |
(new App\ConfigRouteBinder)->bind(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment