Middleware, how to redirect after check Laravel 5

后端 未结 3 926
情深已故
情深已故 2021-01-02 09:18

I need after check if user is logged as editor, to redirect to profile page...

Here is my code:



        
相关标签:
3条回答
  • 2021-01-02 10:05

    I found this to be a less code and less decisions for redirecting users based on roles, Put this in your AuthController.php

    protected function authenticated( $user)
    {
    
        if($user->user_group == '0') {
            return redirect('/dashboard');
        }
    
        return redirect('my-account');
    }
    

    https://laracasts.com/discuss/channels/laravel/how-best-to-redirect-admins-from-users-after-login-authentication

    0 讨论(0)
  • 2021-01-02 10:11

    Go to Kernel.php. It's in app\http. Try to find protected $routeMiddleware in that array you need to add this

    'admin' => \App\Http\Middleware\AdminMiddleware::class
    

    After that it should work fine. Hope this helps anyone who faces the same problem.

    0 讨论(0)
  • 2021-01-02 10:12

    Where did you register your middleware in App\Http\Kernel?

    Is it in protected $middleware = [] or protected $routeMiddleware = [] ?

    If registered in $middleware it will run on each very request thereby causing infinite loop, if so use only $routeMiddleware

    0 讨论(0)
提交回复
热议问题