繁体   English   中英

Laravel表单请求未传递给参数

[英]Laravel Form Request not being passed to argument

我正忙于将应用程序从Laravel 4.2迁移到5.1,并且遇到表单请求问题。 我可能想念的很简单-不确定。

如果SignInRequest成功授权请求,则下面的方法旨在尝试登录。 但是,如果验证通过, SignInRequest会将SignInRequest传递给attemptSignIn ,这会因以下错误而使进程中断:

传递给App \\ Http \\ Controllers \\ Auth \\ AuthController :: attemptSignIn()的参数2必须是App \\ Http \\ Requests \\ SignInRequest的实例

这是有问题的方法(控制器为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;
    }
}

表单请求简单明了,指定了rulesmessagesauthorizereturn 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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM