php - How can I manually return or throw a validation error/exception in Laravel? - Stack Overflow

PHOTO EMBED

Thu Feb 16 2023 01:25:05 GMT+0000 (Coordinated Universal Time)

Saved by @mvieira #php

// Empty data and rules
$validator = \Validator::make([], []);

// Add fields and errors
$validator->errors()->add('fieldName', 'This is the error message');

throw new \Illuminate\Validation\ValidationException($validator);
content_copyCOPY

https://stackoverflow.com/questions/47219542/how-can-i-manually-return-or-throw-a-validation-error-exception-in-laravel