Laravel Validate Array of inputs
I have a form:
<input type="text" name="name[1]">
<input type="text" name="name[2]">
<input type="text" name="name[3]">
<input type="submit" value="Submit">
I created a form validation file with rules:
class formRequest extends FormRequest {
....
public function rules()
{
return ['name.*' => 'unique:names'];
}
public function messages()
{
return ['name.unique' => 'Name is already in DB!'];
}
After submitting a form with a value (for example "John") in an input (for example name[1]
) that already exists in the DB, I get:
SQLSTATE [42S22]: Column not found: 1054 Unknown column 'name.1' in 'where clause' (SQL: select count (*) as a collection from `names` where` name`.`1` = John)
So it handles name.*
both to create a different field name, not to loop through the array.
My Laravel Framework is version 5.4.19. According to the docs , name.*
should work for iterating over the array during validation.
What am I doing wrong?
+3
source to share