我正在将 Laravel 与 Angular 2 一起使用,并且遇到了有关 Laravel 内置登录系统的问题。我可以很好地登录,但是如果用户输入不正确的凭据,它会重定向回上一页,但这并不像我希望的那样工作。我想为重定向定义自定义路径。我已经尝试使用 $loginPath 并将其更改为自定义路径,但该解决方案不起作用。
这是供应商文件“vendor\Illuminate\Foundation\Auth\AuthenticateUsers.php”中的默认函数
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors([
$this->username() => Lang::get('auth.failed'),
]);
}
这是我的登录 Controller “\App\Http\Controllers\Auth\LoginController.php”
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/api/loginCheck';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
}
我希望能够定义自己的路径,在提供不正确的登录凭据时应将用户重定向到何处。如果有人能帮助我,我将不胜感激。
最佳答案
由于您使用使用AuthenticatesUsers;
您可以通过将相同的函数放入“\App\Http\Controllers\Auth\LoginController.php”中来覆盖默认的 sendFailedLoginResponse()
函数
protected function sendFailedLoginResponse()
{
return redirect('/your/url/here');
}
希望这有帮助
关于php - laravel sendFailedLoginResponse() 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39853255/