29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Views 104<br />

Note: All view composers are resolved via the service container, so you may type-hint any<br />

dependencies you need within a composer’s constructor.<br />

Attaching A Composer To Multiple Views<br />

You may attach a view composer to multiple views at once by passing an array of views as the first<br />

argument to the composer method:<br />

.<br />

1 view()->composer(<br />

2 ['profile', 'dashboard'],<br />

3 'App\Http\ViewComposers\MyViewComposer'<br />

4 );<br />

The composer method accepts the * character as a wildcard, allowing you to attach a composer to<br />

all views:<br />

.<br />

1 view()->composer('*', function ($view) {<br />

2 //<br />

3 });<br />

View Creators<br />

View creators are very similar to view composers; however, they are fired immediately when the<br />

view is instantiated instead of waiting until the view is about to render. To register a view creator,<br />

use the creator method:<br />

.<br />

1 view()->creator('profile', 'App\Http\ViewCreators\ProfileCreator');

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!