diff --git a/src/Http/Response/Factory.php b/src/Http/Response/Factory.php index ae3603f11..f04ae155a 100644 --- a/src/Http/Response/Factory.php +++ b/src/Http/Response/Factory.php @@ -9,6 +9,7 @@ use Illuminate\Support\Collection; use Illuminate\Contracts\Pagination\Paginator; use Dingo\Api\Transformer\Factory as TransformerFactory; +use Dingo\Api\Exception\ValidationHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; class Factory @@ -257,6 +258,20 @@ public function errorMethodNotAllowed($message = 'Method Not Allowed') $this->error($message, 405); } + /** + * Return a 422 unprocessable entity exception + * + * @param string $message + * + * @throws Dingo\Api\Exception\ValidationHttpException + * + * @return void + */ + public function errorUnprocessableEntity($message = "Unprocessable Entity") + { + throw new ValidationHttpException($message); + } + /** * Call magic methods beginning with "with". * @@ -272,7 +287,7 @@ public function __call($method, $parameters) if (Str::startsWith($method, 'with')) { return call_user_func_array([$this, Str::camel(substr($method, 4))], $parameters); - // Because PHP won't let us name the method "array" we'll simply watch for it + // Because PHP won't let us name the method "array" we'll simply watch for it // in here and return the new binding. Gross. This is now DEPRECATED and // should not be used. Just return an array or a new response instance. } elseif ($method == 'array') {