On validation fail, I have 2 situations
- one when I display a new error page (this is how it was done before in the app)
- I have a form and I redirect back with input (my problem)
The app is catching the ValidationException in the exceptions Handler – so there is no back with errors for me if a request fails.
Now, I need to return back to the input with errors – from the request class, before it throws the standard ValidationException.
How do I do that from the request class pls?
The code is very basic
I have some rules…
I imagine I need a hook like – validationFailed().. in the request class?
Edit: – not API – regular monolithic PHP
<?php
namespace AppHttpRequests;
use IlluminateFoundationHttpFormRequest;
use Auth;
class LocationCodeRequest 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()
{
$user = Auth::user();
return [
'new_location_code' => 'required|string|max:255|exists:bars,code|not_in:' . $user->locationCode,
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array
*/
public function messages()
{
return [
'new_location_code.not_in' => 'xxx',
'new_location_code.exists' => 'yyy',
];
}
//I need something like this
public function validationFailed()
{
return redirect()->back()->withErrors($this->validator)->withInput();;
}
}