Problems with Middlwares - Laravel 5.4

0

I am using a middleware in Laravel 5.4 and would like it if the logged in user had 2 permission to be redirected to / admin / inscripts. The scope of the handle method looks like this, but redirection does not work. Any ideas?

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);
            }
        }
    }
}
    
asked by anonymous 12.07.2017 / 21:03

1 answer

0

Dude, I think the problem is in your class, because it's missing the instance of RedirectResponse, which contains the headers properties required for redirection, try adding this call.

It will look like this:

use Illuminate \ Support \ Facades \ Auth;

use Illuminate \ Http \ RedirectResponse

    
12.07.2017 / 22:02