Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sqwk opened this issue Feb 6, 2024 · 2 comments
Closed

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

sqwk opened this issue Feb 6, 2024 · 2 comments

Comments

@sqwk
Copy link

sqwk commented Feb 6, 2024

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

@daftspunk
Copy link
Member

Hey @sqwk

Try throwing a ValidationException

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

@sqwk
Copy link
Author

sqwk commented Feb 7, 2024

Thanks, that works.

@sqwk sqwk closed this as completed Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants