My request object isn't receiving old() data when the form fails validation. I am receiving the error messages, but none of the old input data.
I've read a few solutions on similar questions that reference making changes to the redirect on the controller, but that won't solve this problem because the redirect is done by the function referenced below within the FormRequest Class and not the Controller.
Has anyone else experienced this same issue? I've upgraded my instance as I read a few forums that referenced existing bugs, but the issue still exists.
Any help would be appreciated.
Versions: I've tried this on laravel 5.4, 5.7 and 5.8 and none of them are rendering old data.
How I'm doing Request Validation The validation is being done via the standard Requests file that extends FormRequest.
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CustomerManagementRequest extends FormRequest {
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize() {
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules() {
return [
'first_name' => 'required|min:2',
'last_name' => 'required|min:2',
'email' => 'required|min:4',
];
}
}
How I'm trying to access the old data on my view:
value="{{old('first_name')}}"
The Redirect and validation being done in FormRequest The redirect is being done via the Laravel standard FormRequest class.
protected function failedValidation(Validator $validator)
{
throw (new ValidationException($validator))
->errorBag($this->errorBag)
->redirectTo($this->getRedirectUrl());
}
The Validator Response: This is what I see when I vardump the above function. It does have my form data.
Validator {#629 ▼
#data: array:11 [▼
"_token" => "1ynKXxi551UBGbJq6ftLsW6VsClZzmbZdHiHIxyt"
"active_from_date" => "04/04/2019 10:58 PM"
"last_sync_date" => "04/04/2019 11:00 PM"
"first_name" => "Pizza"
"last_name" => "Dough"
"email" => null
"full_phone" => null
"phone" => null
]
}
vardumping the old() parameter in the view returns an empty array []