namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\View;
class ShareUserPreferences
{
public function handle($request, Closure $next)
{
// Example: Share user-specific preferences
$userPreferences = [
'theme' => 'light',
'language' => 'en',
];
View::share('userPreferences', $userPreferences);
return $next($request);
}
}
Add the middleware to the web
middleware group in app/Http/Kernel.php
: