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

[Bug] delete/deleting event not firing when using the delete button #5435

Closed
elythnwaen opened this issue Feb 1, 2024 · 3 comments · Fixed by Laravel-Backpack/docs#548
Closed
Labels

Comments

@elythnwaen
Copy link

Bug report

What I did

Set up deleted/deleting events using the fluent syntax on my fields.
Then pushed the delete button to remove an entry and test it.

What I expected to happen

Execute the code in the event.

What happened

Nothing

What I've already tried to fix it

I tested other events (creating, created, saving, saved, updating, updated), they work fine.

Is it a bug in the latest version of Backpack?

Not sure, I didn’t try it in previous versions, but from what I found while searching for it, it seems like it did work at some point at least.

After I run composer update backpack/crud the bug... is it still there?
Yes

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.2.10 (cli) (built: Aug 29 2023 21:51:44) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies

LARAVEL VERSION:

10.29.0.0

BACKPACK PACKAGE VERSIONS:

backpack/backupmanager: v5.0.0
backpack/basset: 1.2.1
backpack/crud: 6.6.1
backpack/generators: v4.0.2
backpack/permissionmanager: 7.1.0
backpack/pro: 2.0.18
backpack/theme-coreuiv4: 1.1.1

Copy link

welcome bot commented Feb 1, 2024

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@pxpm
Copy link
Contributor

pxpm commented Feb 1, 2024

Hey @elythnwaen thanks for the question.

I am not a fan of using model events in the fields. Some people are, and I think they work "okayish" for simpler scenarios, but then you start hitting this little corner cases and you realize you would just be better by not using the events in the fields.

What does it means actually? So you setup your fields in setupCreateOperation() for example. When creating an entry, Backpack will setup that operation that contains the fields, so the events will be setup.

When you click Delete, it's actually the setupDeleteOperation() that is run, where you don't have your fields setup, so no model events are registered.

You have a few options here:

And... that's it.

Hope it helps, I am going to close this as I don't think there is any issue here, I've just added a note about this scenario to our docs Laravel-Backpack/docs#548

Cheers 🙏

@elythnwaen
Copy link
Author

Setting the events on the setup() method fixed it, thanks!

In case someone check it in the future:

  • Solution a) didn’t work.
  • For solution c) I didn’t manage to get it to work in the model either, but I didn’t try observers.

Anyway issue solved for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants