@jmacdiarmid You don’t use form requests with Livewire components; Livewire handles the lifecycle itself so any validation should be in the component itself as per the error message.
May 19, 2021
7
Level 2
Using Custom Form Request with Livewire v2
I created a form request since I need to customize the field validation messages and passing it to my store method. When opening my modal create form and attempt to submit an empty form, I can see that it's picking up the custom error messages for each field. However, when I try to submit a form with valid data I get the following exception error. How do I use Form Requests with Livewire?
Livewire\Exceptions\MissingRulesException
Missing [$rules/rules()] property/method on Livewire component: [admin.campaign-packages].
Here is my form request:
public function authorize()
{
return true;
}
public function rules(): array
{
return [
'title' => 'required|string',
'duration_id' => 'required|numeric|min:0|not_in:0',
'monthly_impressions' => 'required',
'monthly_investment' => 'required',
'price' => 'required',
];
}
public function messages(): array
{
return [
'duration_id.required' => 'The Commitment Length field is required',
];
}
Please or to participate in this conversation.