1
0
mirror of https://github.com/flarum/core.git synced 2025-10-17 17:56:14 +02:00

Extract model validation into a trait

Also use Laravel’s ValidationException rather than our own custom one
This commit is contained in:
Toby Zerner
2015-07-05 12:25:08 +09:30
parent 04501545e3
commit 53e269fd89
11 changed files with 193 additions and 234 deletions

View File

@@ -1,6 +1,7 @@
<?php namespace Flarum\Api\Actions;
use Flarum\Api\Request;
use Illuminate\Contracts\Validation\ValidationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Flarum\Core\Exceptions\ValidationFailureException;
use Flarum\Core\Exceptions\PermissionDeniedException;
@@ -20,9 +21,9 @@ abstract class JsonApiAction implements ActionInterface
// TODO: Move this error handling code to middleware?
try {
return $this->respond($request);
} catch (ValidationFailureException $e) {
} catch (ValidationException $e) {
$errors = [];
foreach ($e->getErrors()->getMessages() as $field => $messages) {
foreach ($e->errors()->toArray() as $field => $messages) {
$errors[] = [
'detail' => implode("\n", $messages),
'path' => $field