You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DB::transaction(static function() {
$x = new Test();
$x->name = 'test'; # name is not unique, so it will trigger Unicity rule
$x->saveOrFail(); # fails correctly
});
The issue is that in the following method
/**
* Throw a validation exception.
*
* @throws \Watson\Validating\ValidationException
*/
public function throwValidationException()
{
$validator = $this->makeValidator($this->getRules());
throw new ValidationException($validator, $this);
}
The validator is not "triggered" with a ->fail(), so message bag is empty right now.
Then, my transaction rollback and the unique rule does not fails anymore, so the validator has no messages :/
Won't it be better to do something like this :
public function throwValidationException()
{
$validator = $this->makeValidator($this->getRules());
throw new ValidationException(tap($validator)->fails(), $this);
}
in order to populate the validator with errors before anything else in the app happens ?
The text was updated successfully, but these errors were encountered:
I see where you're coming from, however a concern here is that we would now run the rules twice - and this is especially an issue when talking about the Unique rule which would mean duplicate database queries. It's almost like you'd want to persist the last validator that was used (for an isValid or isInvalid call as an instance variable so you could pass it into the exception.
I'm not really sure that I'm going to tackle that any time soon, or that I'm keen to make what could be a substantial breaking change right now. In the meantime, overriding throwValidationException in your app would be the best bet if it solves your use-case. Hope this is helpful!
Hey,
after digging a while on a weird issue, here what I get :
Model rule:
The issue is that in the following method
The validator is not "triggered" with a
->fail()
, so message bag is empty right now.Then, my transaction rollback and the unique rule does not fails anymore, so the validator has no messages :/
Won't it be better to do something like this :
in order to populate the validator with errors before anything else in the app happens ?
The text was updated successfully, but these errors were encountered: