I have some input fields in view blade with name for example
cat[1][0],cat[1][1],cat[2][1] etc .
Now I want to write some validation rules in server side so that each input field is not empty and maximum length of text is 50.
I am facing problem writing the rule for 2d array as name. What I am doing is as below.
$InputsWithtwoDarrayName = $request->cat;
$rules = [];
foreach ($InputsWithtwoDarrayName as $firstKey => $InputsWithtwoDarrayName)
{
foreach ($catQuestion as $secondkey => $qstion)
$rules['cat.' . $firstKey . '.' . $secondkey] = 'required|max:' . 50;
}
$messages = [
'required' => Lang::get('message.assessment.selfAssessment.selfconfirm.error.required'),
];
$validator = Validator::make($InputsWithtwoDarrayName, $rules,$messages);
if ($validator->fails()) {
return Redirect::back();
}
Now my question is what is the proper way of writing rule for 2d array as name?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1JvvcKW
via IFTTT
Aucun commentaire:
Enregistrer un commentaire