I'm busy migrating an app from Laravel 4.2 to 5.1, and am experiencing an issue with Form Requests. It's probably something simple that I'm missing - not really sure.
The method below is meant to attempt a sign in if SignInRequest successfully authorises the request. However, if the validation passes, SignInRequest is not passed to attemptSignIn, which throws the process off with this error:
Argument 2 passed to App\Http\Controllers\Auth\AuthController::attemptSignIn() must be an instance of App\Http\Requests\SignInRequest, none given
This is the method (controller is AuthController) in question, which tries to sign in using a username or an email address:
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;
}
}
The form request is straight-forward, specifying rules, messages and authorize (return true).
If the validation fails, however, SignInRequest is passed to the method, and the errors are shown accordingly.
Am I missing anything here?
SignInRequestin your controller? - mdamiaattemptSignInis a controller method. Are you saying I need to also inject it into the constructor? - Mike RockéttSignInRequestpassed to the method has to be injected or int at constructor - mdamia$this->requestto the form request in the constructor? if so, I would be unable towithErrors()inattemptSignIn, unless errors are passed to the view automatically... - Mike Rockétt