<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Response;

class SetLocale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($request->user() != null)
            app()->setLocale($request->user()->getLocale($request));
        else
            return redirect()->route("users.login");

        return $next($request);
    }
}
