I have isActive middleware where I set 1 to acitive and 0 when user is not active.
isActive.php inMiddleware folder look like this:
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class IsActive
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::check()) {
if (Auth::user()->isActive()) {
return $next($request);
}
}
return redirect('/')->with('nonActive', 'Account is not active');
}
}
and I have method in User model:
public function isActive()
{
if ($this->is_active == 1) {
return true;
}
return false;
}
In Kernel.php in protected $routeMiddleware I add this:
'is.active' => \App\Http\Middleware\IsActive::class,
and I have group middleware in routes and all this works fine.
But, when isActive Middleware return false I can't login with different user. Always get return false as if that user is inactive too until I delete cookies. After deleting I can login just fine with user that is active.
if(Auth::check && Auth::user()->isActive())
php is short circuiting. – adamre-login
because this middleware won't let you. Your options are to logout before attempting to login again or move the IsActive middleware underneath the authentication middleware so that you can login again without logging out. – adam