Laravel View Composers
January 16, 2026
•
1 min read
•
32 views
Table of Contents
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);
Related Posts
Laravel Sanctum API Authentication Complete Guide
Build secure API authentication with Laravel Sanctum for SPAs and mobile apps.
Laravel Rate Limiting: Protect Your Application
Implement rate limiting to protect your Laravel application from abuse.
Laravel Blade Components: Build Reusable UI
Create powerful reusable components with Laravel Blade.
Comments (0)
No comments yet. Be the first to comment!