lundi 30 octobre 2017

Laravel array validation in 5.5 version

Validation code

'event' => 'required|array',
'event.*.start_date_time' => 'required|date_format:Y-m-d|after:today',
'event.*.end_date_time' => 'required|date_format:Y-m-d|after:today',
'event.*.description' => 'required|spam_free',

Error message code

if ($messages->has('event')) {
    $fieldId = 'event';
    $errors [] = getErrorMessage($fieldId, $messages->first($fieldId));
}
if ($messages->has('event.*.start_date_time')) {
    $fieldId = 'event.*.start_date_time';
    $errors [] = getErrorMessage($fieldId, $messages->first($fieldId));
}
if ($messages->has('event.*.end_date_time')) {
    $fieldId = 'event.*.end_date_time';
    $errors [] = getErrorMessage($fieldId, $messages->first($fieldId));
}
if ($messages->has('event.*.description')) {
    $fieldId = 'event.*.description';
    $errors [] = getErrorMessage($fieldId, $messages->first($fieldId));
}

Error message

{
   "fieldld": "event.*.start_date_time",
   "message": "The event.0.start_date_time field is required."
},
{
    "fieldld": "event.*.end_date_time",
    "message": "The event.0.end_date_time field is required."
},
{
    "fieldld": "event.*.description",
    "message": "The event.0.description field is required."
},

Array

event[0].start_date_time:2017-03-22 15:42:22
event[0].end_date_time:2017-03-22 15:42:22
event[0].description:test description

Can anyone help my why its not validation array and why i am not getting proper error message.

Thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2gMcA4T
via IFTTT

Aucun commentaire:

Enregistrer un commentaire