<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

class ShareVariables
{
    public function handle(Request $request, Closure $next)
    {
        view()->share([
            'routeName' => Route::currentRouteName(),
            'locale' => auth()->user()?->locale ?? app()->getLocale(),
            'locales' => config('app.locales') ?? [],
        ]);

        return $next($request);
    }
}
