I am having a form and I have an array of input fields for video urls, now when I validate form if I have multiple invalid fields with video urls, I get the same message for each of the invalid field, since I made my own custom messages. I don't want for each input field the same error message and I don't want the default Laravel error messages for arrays where the name of the field is shown with the error message, instead of that, I would like to have error messages with the value, in this case url written from the user. How to do that?
This is my request file with messages and rules:
public function messages(){
$messages = [
'title.required' => 'Du må ha tittel.',
'type.required' => 'Du må velge artikkeltype.',
'category.required' => 'Du må velge kategori.',
'summary.required' => 'Du må ha inngress.',
'text.required' => 'Du må ha artikkeltekst.',
'active_url' => 'Du må ha gyldig url.',
];
}
public function rules(){
$rules = [
'external_media.*' => 'active_url',
'title' => 'required',
'type' => 'required',
'category' => 'required',
'summary' => 'required',
'text' => 'required',
//'image' => 'required|image|max:20000',
];
return $rules;
}
Updated code to make the question clearer
When I have my request file like this:
public function messages(){
$messages = [
'title.required' => 'Du må ha tittel.',
'type.required' => 'Du må velge artikkeltype.',
'category.required' => 'Du må velge kategori.',
'summary.required' => 'Du må ha inngress.',
'text.required' => 'Du må ha artikkeltekst.',
'external_media.active_url' => 'Du må ha gyldig url.',
];
return $messages;
}
public function rules(){
$rules = [
'external_media.*' => 'active_url',
'title' => 'required',
'type' => 'required',
'category' => 'required',
'summary' => 'required',
'text' => 'required',
//'image' => 'required|image|max:20000',
];
return $rules;
}
I get the output:
The external_media.0 is not a valid URL.
The external_media.1 is not a valid URL.
The external_media.2 is not a valid URL.
Instead of that kind of output I would like to take the value for each of those inputs and have something like:
The htt:/asdfas.com is not a valid URL.