Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.