I'm having trouble with Laravel 5.1 to validate an array.
HTML CODE:
{!! Form::label('information[1][color]', 'Color') !!}
{!! Form::select('information[1][color]', [null => 'Choose your color'] + $product->availableColors()->toArray() , null, ['id' => 'select-color0', 'data-id' => $product->id, 'class' => 'form-control', 'required' => 'required']) !!}
To test if the data is being passed on correctly:
dd($request->all):
"information" => array:1 [▼
1 => array:1 [▼
"color" => "2"
]
]
Validation code:
public function store(Request $request)
{
$rules = [
'information.*.color' => 'required'
];
$validator = Validator::make(Input::all(), $rules);
if($validator->fails()){
dd('Validation fails');
return Redirect::to('index')->withErrors($validator);
} else {
..........
I keep ending up at the page from the dd('Validation fails'). Can someone explain to me what I'm missing here and why the validation isn't working? I'm trying to follow this tutorial: https://mattstauffer.com/blog/form-array-validation-in-laravel-5-2/
I have also tried:
$validator = Validator::make($request->all(), [
'information' => 'required',
'information.*.color' => 'required'
]);
but the validation still fails
Also tried changing the form name:
{!! Form::select('information[][color]', [null => 'Choose your color'] + $product->availableColors()->toArray() , null, ['id' => 'select-color0', 'data-id' => $product->id, 'class' => 'form-control', 'required' => 'required']) !!}
But still no luck yet