Here is an example on how to do.
https://laracasts.com/discuss/channels/laravel/laravel-custom-validation-rule
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello community,
I am creating a suppliers page, where I want to upload a file whenever the admin has a some file, also, i have created a type like citizenship, driving license to identify which document the suppliers has. I already setup my database
public function rules()
{
$rules = [
'name' => 'required',
'name_nepali' => 'required',
'mobile_number' => 'required',
'address_id' => 'required',
'working_days_id' => 'required',
'status_id' => 'required',
'image' => 'mimes:jpg,jpeg,png|nullable',
'file_name.*' => 'mimes:pdf,docs,jpg,png', // this should be nullable too if admin dont want to upload file
'file_type_id.*' => //should be required only file_name has value other wise this should be also nullable too
];
return $rules;
}
by default 1 row will be shown

by clicking + button many row will be added

this above validation should be applied to all repeater row.
Plan
At First I think disabling a select field by default and whenever the file input has value remove to disable attribute from it. but, due to the repetition of row, my code fails to run. so, is there any solution form the Laravel validation ??
If there is any thing from the Laravel validation to check each field of the repeating row that if value is present in file upload , select field should be have value, but if file upload did not contains value, I want to pass null in the database for the select attribute
Any Idea how to do it ?
@vincent15000 well, instead of using laravel custom validation rule there is a validator named required_with which I solve my issue,
here is my code if anybody needs
public function rules()
{
$rules = [
'name' => 'required',
'name_nepali' => 'required',
'mobile_number' => 'required',
'address_id' => 'required',
'working_days_id' => 'required',
'status_id' => 'required',
'image' => 'mimes:jpg,jpeg,png|nullable',
'file_name.*' => 'mimes:pdf,docx,jpg,png|nullable',
'file_type_id.*' => 'required_with:file_name.*,pdf,docx,jpg,png', // this is where i checked if the file_name has value , if it has , this file_type_id is required field.
];
return $rules;
}
Please or to participate in this conversation.