I've followed the simple steps in the Validation documentation:
- Use make:request to create FeedbackFormRequest
- Return true from authorized()
- Add validation rules to rules()
- Declare the controller method to accept FeedbackFormRequest
The controller method gets called with a FeedbackFormRequest, but a) no validation is performed, and b) it is entirely empty. Accessing all() or get($name) returns null for everything, and using dd() shows an empty request. Returning false from authorized() also has no effect.
So while it seems the custom request is completely ignored, $request is an instance of the custom request in the controller. If I change the constructor method declaration to take Request instead, the form values are present. Changing to a named controller method has no effect.
What could I be missing?
Request
class FeedbackFormRequest extends FormRequest
{
public function authorize(): bool {
return true;
}
public function rules(): array {
return [
'name' => 'required|max=100',
'email' => 'required|email|max=100',
'subject' => 'required|max=100',
'body' => 'required|max=750',
'url' => 'max=200',
'g-recaptcha-response' => 'required|recaptcha',
];
}
}
Controller
public function __invoke(FeedbackFormRequest $request) {
$name = $request->get('name');
$subject = $request->get('subject');
return 'Thank you, ' . $name . ', for your message about ' . $subject . '.';
}