Laravel 表单请求未传递给参数

Laravel Form Request not being passed to argument

我正忙于将应用程序从 Laravel 4.2 迁移到 5.1,并且遇到了表单请求问题。这可能是我遗漏的一些简单的东西 - 不太确定。

如果 SignInRequest 成功授权请求,则以下方法旨在尝试登录。但是,如果验证通过,SignInRequest 不会传递给 attemptSignIn,这会导致进程关闭并出现以下错误:

Argument 2 passed to App\Http\Controllers\Auth\AuthController::attemptSignIn() must be an instance of App\Http\Requests\SignInRequest, none given

这是有问题的方法(控制器是 AuthController),它尝试使用用户名或电子邮件地址登录:

public function attemptSignIn($type = 'regular', SignInRequest $request)
{
    switch ($type) {
        case 'regular':
            $identifierFieldName = 'account_identifier';
            $field = filter_var($request->input($identifierFieldName), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
            $request->merge([$field => $request->input($identifierFieldName)]);
            $specifics = $request->only($field, 'passphrase');
            $specifics['activated'] = (int) true;
            if ($this->auth->attempt($specifics)) {
                return redirect()->intended($this->redirectPath);
            } else {
                return redirect($this->signInPath)
                    ->with('authError', "The credentials you've provided are incorrect.")
                    ->with('authErrorType', 'warning')
                    ->withInput($request->only($identifierFieldName))
                    ->withErrors();
            }
            break;

        case 'oota':

            break;

        default:
            return redirect($this->signInPath);
            break;
    }
}

表单请求很简单,指定了 rulesmessagesauthorize (return true)。

但是,如果验证失败,SignInRequest 将传递给该方法,并相应地显示错误。

我在这里遗漏了什么吗?

use \path\to\your\ClassRequest as MyRequest

protected $myrequest;

public function __construct(\path\to\your\ClassRequest $request){
   $this -> myrequest = $request; // use directly in your method or any method
}

希望对您有所帮助。

public function post_form(MyRequest $request) {
  your code here

}