<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;

class AuthLogin
{
    /**
     * Handle an incoming request.
     * Redirect user to admin login page if he has not the previliage to access the admin panel
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (  !Auth::check() ) 
        {
            $url = url()->current();
            $route = app('router')->getRoutes()->match(app('request')->create($url))->action['as'];
            if(in_array($route,['web.reservation','web.reservation.status','web.reservation.continue','web.time.reservation','web.reservation.bill']))
            {
                session()->put(['book'=>'on']);   
            }
            return redirect(getCurrentLocale().'/login');
        }

        return $next($request);
    }
}
