Skip to content

Instantly share code, notes, and snippets.

@boyhagemann
Created October 4, 2013 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boyhagemann/6822567 to your computer and use it in GitHub Desktop.
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.
// 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