Php Laravel 5内置用户身份验证

Php Laravel 5内置用户身份验证,php,authentication,laravel-5,Php,Authentication,Laravel 5,我正在尝试使用Laravel 5内置用户身份验证。在这方面,我希望在成功登录后将用户重定向到某个路由/页面/控制器。我正在尝试更改compiled.php文件的代码。我正在尝试更改下面代码的/home,但它不起作用 trait AuthenticatesAndRegistersUsers { protected $auth; protected $registrar; public function getRegister()

我正在尝试使用Laravel 5内置用户身份验证。在这方面,我希望在成功登录后将用户重定向到某个路由/页面/控制器。我正在尝试更改compiled.php文件的代码。我正在尝试更改下面代码的
/home
,但它不起作用

trait AuthenticatesAndRegistersUsers
    {
        protected $auth;
        protected $registrar;
        public function getRegister()
        {
            return view('auth.register');
        }
        public function postRegister(Request $request)
        {
            $validator = $this->registrar->validator($request->all());
            if ($validator->fails()) {
                $this->throwValidationException($request, $validator);
            }
            $this->auth->login($this->registrar->create($request->all()));
            return redirect($this->redirectPath());
        }
        public function getLogin()
        {
            return view('auth.login');
        }
        public function postLogin(Request $request)
        {
            $this->validate($request, array('email' => 'required|email', 'password' => 'required'));
            $credentials = $request->only('email', 'password');
            if ($this->auth->attempt($credentials, $request->has('remember'))) {
                return redirect()->intended($this->redirectPath());
            }
            return redirect($this->loginPath())->withInput($request->only('email', 'remember'))->withErrors(array('email' => $this->getFailedLoginMessage()));
        }
        protected function getFailedLoginMessage()
        {
            return 'These credentials do not match our records.';
        }
        public function getLogout()
        {
            $this->auth->logout();
            return redirect('/home');
        }
        public function redirectPath()
        {
            if (property_exists($this, 'redirectPath')) 
            {
                return $this->redirectPath;
            }
            return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
        }
        public function loginPath()
        {
            return property_exists($this, 'loginPath') ? $this->loginPath : '/auth/login';
        }
    }

谢谢

您不应该在
compiled.php

RedirectIfAuthenticated
中间件更改中

return new RedirectResponse(url('/home'));

这基本上重定向登录用户到所需的路径,一旦登录用户返回到网站。 因此,
handle
函数如下所示

public function handle($request, Closure $next) {

    if ($this->auth->check())
    {
        return new RedirectResponse(url('/'));
    }

    return $next($request);
}
然后在
AuthController

public $redirectTo = '/';
public $redirectAfterLogout = '/';

因此,成功登录后,用户将被重定向到
重定向到
,注销后,用户将被重定向到
在注销后重定向

您不应该在
compiled.php中更改任何内容

RedirectIfAuthenticated
中间件更改中

return new RedirectResponse(url('/home'));

这基本上重定向登录用户到所需的路径,一旦登录用户返回到网站。 因此,
handle
函数如下所示

public function handle($request, Closure $next) {

    if ($this->auth->check())
    {
        return new RedirectResponse(url('/'));
    }

    return $next($request);
}
然后在
AuthController

public $redirectTo = '/';
public $redirectAfterLogout = '/';

因此,成功登录后,用户将被重定向到
重定向到
,注销后,用户将被重定向到
redirectAfterLogout

谢谢@pinkal vansia。如果未找到预期路线,会发生什么情况??谢谢你在说什么路线?总的来说,您将获得未找到的路线。谢谢@pinkal vansia。我在compiled.php第7319行:Undefined offset:1中得到了这个错误
ErrorException。我得到了这个“[Symfony\Component\Debug\Exception\FatalErrorException]调用Undefined method illighted\Foundation\Application::getCachedCompil ePath()`谢谢@pinkal vansia。如果未找到预期路线,会发生什么情况??谢谢你在说什么路线?总的来说,您将获得未找到的路线。谢谢@pinkal vansia。我在compiled.php第7319行:Undefined offset:1中得到了这个错误
ErrorException。我得到了对Undefined method illighted\Foundation\Application::getCachedCompil ePath()的“[Symfony\Component\Debug\Exception\FatalErrorException]调用`