Laravel

Laravel View Composers

January 16, 2026 1 min read 32 views

View composers:

Register Composer

// AppServiceProvider
View::composer('layouts.app', function ($view) {
    $view->with('notifications', auth()->user()?->notifications);
});

Composer Class

class NavigationComposer
{
    public function compose(View $view)
    {
        $view->with('menu', Menu::all());
    }
}

View::composer('partials.nav', NavigationComposer::class);

Multiple Views

View::composer(['profile', 'dashboard'], function ($view) {
    $view->with('user', auth()->user());
});

Wildcard

View::composer('admin.*', AdminComposer::class);
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!