Last active
November 16, 2017 16:18
-
-
Save verschuur/5687293ef402a4e20b5a0881674fb04d to your computer and use it in GitHub Desktop.
Laravel ViewComposerServiceProvider example with several registering options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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