I have a table called agents
and I want to check in middleware
when the agent is trying to log in, the agent is active or not
public function handle($request, Closure $next) { $user = $this->auth->user(); if(agentmodel::where('status') == 'active'){ true; }else{ false; } }
Advertisement
Answer
You have to return the request in the middleware so it continues
public function handle($request, Closure $next) { // Declared but not used $id = auth()->id(); // If agent belongs to a user if (Appagentmodel::where('user_id', $id)->first()->status == 'active') { return $next($request); } Session::flush(); return back()->with('error', 'Your account is not active'); }
This will redirect back and not allow the user to continue if the agent is not active