Skip to content

Commit e2432eb

Browse files
committed
Model compatibility with Laravel ValidationException
1 parent eea7508 commit e2432eb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Database/ModelException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ class ModelException extends ValidationException
1616
protected $model;
1717

1818
/**
19-
* __construct recevies the troublesome model
19+
* __construct receives the troublesome model
2020
*/
2121
public function __construct(Model $model)
2222
{
23+
parent::__construct($model->errors());
24+
2325
$this->model = $model;
24-
$this->errors = $model->errors();
25-
$this->evalErrors();
2626
}
2727

2828
/**

src/Exception/ValidationException.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use Validator as ValidatorFacade;
44
use Illuminate\Validation\ValidationException as ValidationExceptionBase;
55
use Illuminate\Validation\Validator;
6+
use Illuminate\Support\MessageBag;
67
use InvalidArgumentException;
78

89
/**
@@ -55,6 +56,10 @@ protected function resolveToValidator($validation)
5556
$validator = ValidatorFacade::make([], []);
5657
$validator->errors()->merge($validation);
5758
}
59+
elseif ($validation instanceof MessageBag) {
60+
$validator = ValidatorFacade::make([], []);
61+
$validator->errors()->merge($validation->messages());
62+
}
5863

5964
if (!$validator instanceof Validator) {
6065
throw new InvalidArgumentException('ValidationException constructor requires instance of Validator or array');

0 commit comments

Comments
 (0)