fntneves / laravel-transactional-events

Transaction-aware Event Dispatcher for Laravel
MIT License
314 stars 28 forks source link

Why are Eloquent events excluded? #18

Closed flyingL123 closed 5 years ago

flyingL123 commented 5 years ago

This is probably a silly question, but why are Eloquent events excluded by default in the config file? I'm calling save on an eloquent model within a transaction, as well as performing some other functions. Sometimes the transaction doesn't commit because an Exception is throw, which means the model is not saved. However, since I am binding an even to the created event of that model, the event is being triggered even if the transaction doesn't commit.

Googling around for solutions led me to this package, which seems great. However, I guess I will have to alter the config so that Eloquent events are not excluded, right?

Is there any reason not to do this? Is there a reason Eloquent events are being excluded? If events dispatched outside of a transaction are not effected, why not have this package work on all events?

flyingL123 commented 5 years ago

Sorry, like I said, it was a silly question. I didn't realize that the events I define on the models are in the App\Events namespace. So excluding the eloquent.* events is unrelated. Those are the framework events and are supposed to be excluded.

Can I just say, this may be the greatest package of all time. I literally installed it and my problem was fixed. Not one single line of code needed to change.

Thank you for creating this!

fntneves commented 5 years ago

Hi @flyingL123,

Thank you for your comments, they are really motivating and I'm glad to know you're enjoying the package.

Just to complement your last comment, I've opted out to disable eloquent.* because most applications may be relying on them to perform actions no matter what's the outcome of the transaction. So, consider this as safety.

Once again, thank you for using this package!