lundi 28 janvier 2019

Laravel sibling attribute base validation

I have an array of attributes in my payload as follow:

{
    "courier_code" : "shipadelivery",
    "rule" : [ 
                {
                    "attribute" : "day",
                    "operator" : "eq",
                    "value" : "tue"
                }
            ],
    "is_active" : true,
    "priority" : 2
}

here what i need to validate is if the attribute is day then the value should be in ['mon','tue','wed','thu','fri','sat','sun'] and the operator should be eq

How should i do the validation using the exising attribut params. I already did the validation for this not examine the attribute as follow

        $rules = [
            'courier_code' => 'required|exists:shipment_companies,code',
            'is_active' => 'required|boolean',
            'priority' => 'required|integer',
            'rule' => 'required',
            'rule.*.attribute' => 'required',
            'rule.*.attribute' => 'required|in:'.$attributes,
            'rule.*.value' => 'required',
            'rule.*.operator' => 'required|in:'.$operators,
        ];



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2D1bxc7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire