Laravel Fail Validation Helper

if (! function_exists('fail_validation')) {
    function fail_validation(string $key, string $message)
        throw ValidationException::withMessages([$key => $message]);


Laravel's validation system takes care of all the dirty work for you, including redirecting the user back to the previous page with the correct status code and storing your errors on the session for easier display. This helper allows you to take advantage of all the heavy lifting once your initial validation has passed, allowing you to fail validation when a Stripe HTTP request fails, for example.