Created
October 4, 2013 08:08
-
-
Save boyhagemann/6822567 to your computer and use it in GitHub Desktop.
Using the DeSmart\Layout package, you can dispatch the resourceful Crud routes and attach the returned view to your layout. This is an example how you can have any page have a default layout.
This file contains 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
// Dispatch the route and catch the returned View. | |
// Create a new layout and assign the View to the main content variable. | |
Route::filter('layout', function(Illuminate\Routing\Route $route) { | |
// We have to transform the 'id' variable to the name of the resource, e.g. 'news'. | |
// Only then the variables match and the route will be correct. | |
$params = $route->getParameters() + array('id' => current($route->getParameters())); | |
// Dispatch the original route and catch the view output. | |
$content = App::make('DeSmart\Layout\Layout')->dispatch($route->getAction(), $params); | |
// Assign the view to the layout and we are done. | |
return View::make('layouts.default', compact('content')); | |
}); | |
// Use the 'layout' filter for all url requests | |
Route::when('*', 'layout'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment