Route [login] not defined

前端 未结 14 1896
無奈伤痛
無奈伤痛 2020-12-02 15:15

Trying to play with Laravel today for the first time. I am getting the following error when I attempt to visit localhost/project/public:

InvalidArgume

14条回答
  •  独厮守ぢ
    2020-12-02 16:02

    Laravel ^5.7

    The Authenticate Middleware

    Laravel ^5.7 includes new middleware to handle and redirect unauthenticated users.

    It works well with "web" guard... of course the "login" route (or whatever you name your login route) should be defined in web.php.

    the problem is when your are using custom guard. Different guard would redirect unauthenticated users to different route.

    here's a quick workaround based on John's response (it works for me).


    app/Http/Middleware/Authenticate.php

    guards = $guards;
    
            return parent::handle($request, $next, ...$guards);
        }
    
    
    
    
        /**
         * Get the path the user should be redirected to when they are not authenticated.
         *
         * @param  \Illuminate\Http\Request  $request
         * @return string
         */
        protected function redirectTo($request)
        {
            if (! $request->expectsJson()) {
    
                if (in_array('admin', $this->guards)) {
    
                    return route('admin.login');
                }
    
                return route('login');
            }
        }
    }
    

    Source : Issue #26292

提交回复
热议问题