title: Laravel base controller methods
body: <p>I'm learning how to use Laravel by writing a little test application. So far its going really well, and I'm excited by all the features of the framework. However, I keep hitting a wall when I try to apply a specific design pattern.</p>
  
  <p>I've currently got a set up where I can set the html titles, keywords and description with default values in the base controller, and then optionally change them in the child controller that extends it:</p>
  
  <p>Base controller</p>
  
  <pre><code>protected function setupLayout()
  {
      $this-&gt;layout-&gt;title = 'Wow website';
      $this-&gt;layout-&gt;desc = 'Much technical';
      $this-&gt;layout-&gt;keys = 'so html, very javascript';
  
      $foot = View::make('mod.footerDefault');
      $this-&gt;layout-&gt;footer = $foot;
  }
  </code></pre>
  
  <p>Child controller</p>
  
  <pre><code>public function getContact()
  {
      $this-&gt;title = 'Contact page of contactness';
      // Could also override the desc and keys if desired,
      // but I'll just let them default here
  
      $data = 'wow';
      $view = View::make('main.home', $data)
          -&gt;nest('vid', 'mod.video')
          -&gt;nest('list', 'mod.list');
  
      $this-&gt;layout-&gt;content = $view;
  }
  </code></pre>
  
  <p>This is all gravy, but what if I have an object that I've interacted with, such as a menu class, that needs to be recompiled into a string of HTML? Is there a method in laravel that is similar to the setupLayout() method which is called automatically, but each time the View::make method is invoked?</p>
  
  <p>(More examples...just to illustrate)</p>
  
  <p>Base controller</p>
  
  <pre><code>protected function setupLayout()
  {
       $this-&gt;menu = newMenu();
       $this-&gt;menu-&gt;items[0] = ['contact-us', 'Contact us'];
       $this-&gt;menu-&gt;items[1] = ['about-us', 'About us'];
       $this-&gt;menuString = $this-&gt;menu-&gt;getString();
  }
  </code></pre>
  
  <p>Child controller</p>
  
  <pre><code>public function getContact()
  {
      $this-&gt;menu-&gt;addItem(['log-out', 'Log out']);
      // Now $this-&gt;menuString must be recalculated.
      // Ideally want to avoid having to call a method from the base controller
      // every time the child controller calls View::make
  
      $view = View::make('main.home')
      $this-&gt;layout-&gt;content = $view;
  }
  </code></pre>
  
  <p>I know there is such a thing as view composers, but I dont think these are called on View::make().</p>