I found a partial answer to my question:
The code of the Form Request class:
public function rules()
{
$request = $this->instance()->all();
$rules = [];
$images = $request['files'];
$images_rules = 'required|image|mimes:jpeg,png|max:5120';
if (count($images) > 0) {
foreach ($images as $key => $image) {
$rules['files.'.$key] = $images_rules;
}
}
return $rules;
}
protected function createMessages()
{
$request = $this->instance()->all();
$messages = [];
$images = $request['files'];
if (count($images) > 0) {
foreach ($images as $key => $image) {
$messages['files.'.$key.'.required'] = 'Select files!';
$messages['files.'.$key.'.image'] = 'Only images!';
$messages['files.'.$key.'.mimes'] = 'Only jpeg and png!';
$messages['files.'.$key.'.size'] = 'File max 5M';
}
}
return $messages;
}
public function messages()
{
return $this->createMessages();
}
The rules works fine. I have a problem with errors messages: in my view I get an error message only when input is empty (required error messsage). When the other rules are not respected I get no message.
I have tested this system with an other input array (a select list). This work fine also for messages.
Have you an idea about this problem?
Thanks.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community