dwightwatson / validating

Automatically validating Eloquent models for Laravel
MIT License
968 stars 76 forks source link

Add custom error to Model #206

Closed wemteqdev closed 5 years ago

wemteqdev commented 5 years ago

Is it possible to add custom validation error to model? something like following.

if (!$video->published()){ $video->addError('notification', 'can be sent for only published videos') }

dwightwatson commented 5 years ago

You could use setErrors to manually set the error bag, I suppose in this instance you would want to get the error bag, append to it and set it again. However, it's not something I'd be looking to support normally. For your example, it sounds more like something that would be handled by a policy rather than validation.