mardi 29 janvier 2019

Throw custom exception in Laravel validation error format

How do I throw a validation message in a same format $this->validate($request); method return

I wrote my custom validation like as below

class ShipmentRuleCreationValidation
{
    public function validate($request)
    {
        $days = ['mon','tue','wed','thu','fri','sat','sun'];
        for ($i=0; $i<count($request['rule']); $i++ ){
            if($request['rule'][$i]['attribute'] == "day"){
                if(!in_array($request['rule'][$i]['value'],$days)){
                    throw new \Illuminate\Validation\ValidationException(['rule.'.$i.'value' => 'Invalid day value']);
                }
            }
        }

    }
}

but it is throw me

(1/1) ErrorException Trying to get property 'original' of non-object



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

Aucun commentaire:

Enregistrer un commentaire