dongxian3418 2016-10-04 13:10
浏览 221
已采纳

laravel sendFailedLoginResponse()覆盖

I'm using Laravel with Angular 2 and I've run into an issue regarding the log in system that is built-in to Laravel. I can log in just fine, but if the user enters incorrect credentials it redirects back to the previous page, but this doesn't work the way I want it to. I want to define a custom path for the redirect. I already tried to use $loginPath and change that to a custom path, but that solution doens't work.

This is the default function from the vendor file "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'),
        ]);
}

And this is my login 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']);
    }
}

I want to be able to define my own path to where the user should be redirected upon giving incorrect log in credentials. If anyone could help me out, that'd be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • drau67562 2016-10-04 13:58
    关注

    Since you use use AuthenticatesUsers; you can just override the default sendFailedLoginResponse() function by putting the same function in your "\App\Http\Controllers\Auth\LoginController.php"

    protected function sendFailedLoginResponse()
    {
        return redirect('/your/url/here');
    }
    

    Hope this helps

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件