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've created 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 the form with value (e.g. 'John') in input (e.g. name[1]), which already exists in the DB, I get:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name.1' in 'where clause' (SQL: select count(*) as aggregate from `names` where `name`.`1` = John)
So it's treating name.* as for creating another field name, instead of looping through the array.
My Laravel Framework is version 5.4.19. According to the docs, the name.* should work to iterate through an array during validation.
What I am doing wrong?