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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire