There is no license information available for the latest version (1.2.0) of this package.

Simple page structure controller for Laravel4

Installs: 584

Dependents: 3

Stars: 9

Watchers: 9

Forks: 1

Open Issues: 2

1.2.0 2014-10-23 08:48 UTC


Build Status

Add desmart\laravel-layout as a requirement to composer.json:

  "require": {
    "desmart/laravel-layout": "1.2.*"

Update your packages with composer update or install with composer install.

In app/config/app.php add:

  • 'DeSmart\Layout\LayoutServiceProvider', to providers
  • 'Layout' => 'DeSmart\Layout\Facades\Layout', to aliases.


This package provides DeSmart\Layout\Controller class which works like normal page controller.
However it can be used to describe complete page structure.

To do this simply define $layout which is basic page template, and $structure which is an array with section block definition.

Section block is a list of callbacks (let's call them actions) which will be run and put in a defined place in template.

Sample page template

<!DOCTYPE html>
    <div class="container">
      <div class="main">{{ $main }}</div>
      <div class="right">{{ $right }}</div>

Sample controller

class SampleController extends \DeSmart\Layout\Controller {

  protected $layout = 'layouts.default';

  protected $structure = array(
    'main' => array(
    'right' => array(

  public function showProducts() {
    $this->structure['main'] = array(

    return $this->execute();

  public function showOne() {
    $this->structure['main'] = array(

    return $this->execute();


Sample route

Route::get('/', 'SampleController@execute');
Route::get('/products', 'SampleController@showProducts');
Route::get('/products/{product_id}', 'SampleController@showOne');


Each action is a callback string which will be called during DeSmart\Layout\Controller@execute call.
Every action can get params defined in route, just define them as function arguments (public function showOne($product_id) {}).

Layout facade

This package provides Layout facade with method dispatch. It can be used to execute action directly in template.

<header>{{ Layout::dispatch('HomeController@head') }}</header>

dispatch() can take array argument with named callback arguments:

class FancyController {

  public function test($name, $title = 'sir. ') {}


<header> {{ Layout::dispatch('FancyController@test', array('name' => 'Hans')) }} </header>

Notice, that it takes care with default arguments.


This package is provided as is. For now it's only a concept and the whole idea can change.

Just treat it as early alpha version.