0
I am using a middleware on Laravel 5.4 and would like if the logged in user had permission 2 to be redirected to /admin/signups. The scope of the Handle method looks like this, but the redirect doesn’t work. Any idea?
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class AdminMiddleware{
public function handle($request, Closure $next){
// SE O USUÁRIO NÃO ESTIVER LOGADO REDIRECIONA PARA O LOGIN
if (!Auth::check()) {
return redirect('login');
}else{
// SE O USUÁRIO QUE LOGOU FOR CANDIDATO REDIRECIONA PARA MINHA CONTA
if($request->user()->permissao !== 2){
return redirect('/minhaconta');
}elseif($request->user()->permissao === 2){
return redirect('/admin/inscricoes');
}else{
return $next($request);
}
}
}
}
Where did you register middleware in the app? It’s on some route or all requests?
– Woss
What happens, where it’s set up?
– novic
@Andersoncarloswoss I have registered in the routes that have the prefix 'admin'. Think I should register in all?
– Fellipe Botelho
Already tried to use operators
!=
and==
? I think the value is coming as a string and thus is different from an integer.– Woss
You’re doing it for the logged-in right? exchange the $request by the auth()->user()->permission helper, also put some dd() so we know what’s going on.
– PV Telles