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.

Package Development 300<br />

Package views are referenced using a double-colon package::view syntax. So, you may load the<br />

admin view from the courier package like so:<br />

.<br />

1 Route::get('admin', function () {<br />

2 return view('courier::admin');<br />

3 });<br />

Overriding Package Views<br />

When you use the loadViewsFrom method, Laravel actually registers two locations for your views:<br />

one in the application’s resources/views/vendor directory and one in the directory you specify.<br />

So, using our courier example: when requesting a package view, Laravel will first check if a custom<br />

version of the view has been provided by the developer in resources/views/vendor/courier. Then,<br />

if the view has not been customized, Laravel will search the package view directory you specified in<br />

your call to loadViewsFrom. This makes it easy for end-users to customize / override your package’s<br />

views.<br />

Publishing Views<br />

If you would like to make your views available for publishing to the application’s resources/views/vendor<br />

directory, you may use the service provider’s publishes method. The publishes method accepts<br />

an array of package view paths and their corresponding publish locations.<br />

.<br />

1 /**<br />

2 * Perform post-registration booting of services.<br />

3 *<br />

4 * @return void<br />

5 */<br />

6 public function boot()<br />

7 {<br />

8 $this->loadViewsFrom(__DIR__.'/path/to/views', 'courier');<br />

9<br />

10 $this->publishes([<br />

11 __DIR__.'/path/to/views' => base_path('resources/views/vendor/courier'),<br />

12 ]);<br />

13 }<br />

Now, when users of your package execute Laravel’s vendor:publish Artisan command, your views<br />

package’s will be copied to the specified location.

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

Saved successfully!

Ooh no, something went wrong!