Easily raise validation error with custom message
When dealing with complex validation scenarios it is often useful to raise the validation exception manually. Or there may be some scenarios where you can’t do a validation before doing a lot of other actions or queries.
It is as simple as throwing a Illuminate\Validation\ValidationException
:
use Illuminate\Validation\ValidationException;
throw ValidationException::withMessages(['field_name' => 'This value is incorrect']);
•
•
•
If you like this article consider tweeting or check out my other TILs.