<?php

namespace App\Http\Middleware;

use Auth;
use Closure;
use Redirect;
use App\Traits\LogUtils;

class UserAuthMiddleware
{

    use LogUtils;
    public function handle($request, Closure $next)
    {

        $this->printf("I am in UserAuthMiddleware");

        if (!Auth::check()) {
            return Redirect::route('login');
        }

        $user = Auth::user();

        if ($user->is_delete == 1) {

            return Redirect::route('auth.deactive.logout');

        }

        if ($user->status == 0) {

            return Redirect::route('auth.deactive.logout')->with('error', 'Your Account has been deactivated');

        }
        return $next($request);
    }
}
