douanrang4728
2018-10-10 13:00 阅读 334

Laravel 5.7登录重定向到404页面

I'm having an issue now after installing laravel-math-captcha though it was working fine for 2 days with Laravel 5.7 when I login with correct credentials I get redirected to a 404 page. I debug the login process

die($this->sendLoginResponse($request));

and I get

HTTP/1.0 302 Found Cache-Control: no-cache, private Date: Wed, 10 Oct 2018 13:01:35 GMT Location: http://127.0.0.1:9500/404 Redirecting to http://127.0.0.1:9500/404. 

When I navigate to /home I find that I successfully logged in

Any idea how to solve this issue and why did it appear?

[Update]

LoginController

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{

  public $decayMinutes = 1;
  public $maxAttempts = 10;

  use AuthenticatesUsers;

  protected $redirectTo = '/';

  public function __construct()
  {
    $this->middleware('guest', ['except' => 'logout']);
  }

}

Login function from AuthenticatesUsers

public function login(Request $request)
{
    $this->validateLogin($request);

    if ($this->hasTooManyLoginAttempts($request)) {
        $this->fireLockoutEvent($request);

        return $this->sendLockoutResponse($request);
    }

    if ($this->attemptLogin($request)) {
        return $this->sendLoginResponse($request);
    }

    $this->incrementLoginAttempts($request);

    return $this->sendFailedLoginResponse($request);
}
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • donglin1692 donglin1692 2018-10-10 13:06

    I think your form action url is wrong, could you update your post and show us how you built your form? If you take a look at the response you got, you can clearly see that you called 404 page. If this is not the case, then please include the LoginController code too

    Try and change the line inside the LoginController to:

    protected $redirectTo = '/home';
    
    点赞 评论 复制链接分享
  • dqm4675 dqm4675 2018-10-11 05:38

    Hi I think you would need to check your routes.php.

    Probably the error is there, if you could upload your routes.php would be good.

    But consider the comment above.

    You are redirecting to '/' in the controller, you need to make sure that in routes.php you have assigned a view to '/'.

    点赞 评论 复制链接分享
  • duan5801 duan5801 2018-10-11 13:43

    Created a custom login controller which was working fine then checked the built-in login form and it just worked without any changes. The protected $redirectTo = '/'; as the same as before.

    点赞 评论 复制链接分享

相关推荐