Laravel 5.3 继续前往 /home 视图

Laravel 5.3 keep going to /home view

请帮我解决这个 Auth 重定向问题。

目前我正在使用 laravel 5.3.22。我已经放了

protected $redirectTo = 'dashboard';

进入我的登录控制器。

然后我在浏览器中测试重定向:

http://myapp.localhost/login

它正确显示 "Login Page"。然后我继续登录,它正确地将我重定向到 "Dashboard"。

问题就在这里。成功登录后,如果我尝试去

http://myapp.localhost/login

它将我重定向到 "Home",但它不可用。它应该去 "Dashboard".

请帮助我。

您需要添加到 routes.php 路线 首先创建 1- 带 Artisan 的控制器 php make::HomeController 2- 在应用程序目录中添加路由 Route::get('/home', function () { return view('home'); }); 3- 稍后您需要在您的目录 resources/views/home.blade.php

中创建一个名为 home.blade.php 的页面

这很奇怪... 你清除过缓存吗?

$ php artisan cache:clear
$ php artisan config:clear
$ php artisan clear-compiled

如果您没有成功执行上述步骤,请跳转到以下方法:LoginController 使用 AuthenticatesUsers 特性,它使用 RedirectsUsers 特性,它拥有 redirectPath() 方法。在这种情况下,您可以像这样覆盖它:

public function redirectPath()
{
    return '/Dashboard';
}

正如您可能已经想到的那样,您必须将代码片段放入 LoginController。

请查看 folder /app/http/Middleware/ 那里您应该会看到以下文件 RedirectIfAuthenticated.php

更改自:

public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/home');
        }

        return $next($request);

收件人:

public function handle($request, Closure $next, $guard = null)
    {
        if (Auth::guard($guard)->check()) {
            return redirect('/dashboard');
        }

        return $next($request);

你应该没事的。

请注意,

/app/Controllers/Auth/LoginController.php

指示您在登录后被发送到哪里,而

/app/Middleware/RedirectIfAuthenticated.php

如果在成功登录后请求 domain.app/login 请求,则控制发送用户的位置。