octobercms / october

Self-hosted CMS platform based on the Laravel PHP Framework.

Home Page:https://octobercms.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returning False in model.before…() Still Flashes Success

sqwk opened this issue · comments

commented

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.)

commented

Hey @sqwk

Try throwing a ValidationException

throw new \ValidationException(['id' => 'Not allowed to delete model']);
commented

Thanks, that works.