<?php

namespace App\Http\Middleware;

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

class AccountMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (Auth::check() && Auth::user()->role_id == 2 || Auth::check() && Auth::user()->role_id == 3) {
            if (Auth::user()->status == 0) {
                Auth::logout();
                notify()->error("Your account is blocked, please contact admin", "Wrong");
                return back();
            }
            return $next($request);
        }
        return Redirect()->route('home');
    }
}
