Returning False in model.before…() Still Flashes Success
sqwk opened this issue · comments
When canceling any save, delete, update operation in beforeCreate()
, beforeUpdate()
, beforeDelete()
, … a success message is still flashed to the user.
public function beforeDelete()
{
if (some check) {
Flash::error('Not allowed to delete model');
return false;
}
}
In the example above the delete is cancelled by the return false
and the Flash::error is also shown. However the Flash::error is hidden behind the default Flash::success.
Shouldn't the success flash message not be shown at all, since the before method returned false?
(I am aware that a throw new ApplicationException('Not allowed to delete model.');
works fine, but I quite like the look of the flash message.)
Hey @sqwk
Try throwing a ValidationException
throw new \ValidationException(['id' => 'Not allowed to delete model']);
Thanks, that works.