ProfileComposer
5
Пример как удобно передать во все view какую-либо переменную, в данном случаи объект с user
app/Http/View/Composers/ProfileComposer.php
<?php namespace App\Http\View\Composers; use Illuminate\View\View; class ProfileComposer{ /** * Bind data to the view. * * @param \Illuminate\View\View $view * @return void */ public function compose(View $view) { $view->with('user', auth()->user()); }}
app/Providers/ViewServiceProvider.php
<?php namespace App\Providers; use App\Http\View\Composers\ProfileComposer;use App\Http\View\Composers\SubscriptionComposer;use Illuminate\Support\ServiceProvider;use Illuminate\Support\Facades\View; class ViewServiceProvider extends ServiceProvider{ /** * Register services. * * @return void */ public function register() { // } /** * Bootstrap services. * * @return void */ public function boot() { View::composer("profile.*", ProfileComposer::class); }}