Skip to content

Instantly share code, notes, and snippets.

@verschuur
Last active November 16, 2017 16:18
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 verschuur/5687293ef402a4e20b5a0881674fb04d to your computer and use it in GitHub Desktop.
Save verschuur/5687293ef402a4e20b5a0881674fb04d to your computer and use it in GitHub Desktop.
Laravel ViewComposerServiceProvider example with several registering options
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewComposerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
// Closure based composers...
View::composer('my.view', function ($view) {
//
});
// Single class based composers...
View::composer(
'my.view', 'App\ViewComposers\MyViewComposer'
);
// Single class based composer registered to multiple views
View::composer(
['my.view', 'another.view'],
'App\ViewComposers\MyViewComposer'
);
// Registering several composers at once
View::composers(
[
'App\ViewComposers\MyViewComposer' => 'my.view',
'App\ViewComposers\AnotherViewComposer' => 'another.view'
]
);
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment