Closed jonagoldman closed 6 years ago
Thank you for the PR, Jona! It would be great to have a tests for this events too. And it would be great to have small description of the decision to have 2nd argument (boolean flag $halt
) as false
, what does it do?
The 2nd argument is used to allow/disallow the event listener to stop the propagation.
This will be used in events that are fired before the method execution.
For example, if we had an accepting
event, it will like like this:
/**
* Mark entity as accepted.
*
* @return void
*/
public function accept()
{
$this->fireModelEvent('accepting'); // $halt defaults to true
$this->setAcceptedFlag()->save();
$this->fireModelEvent('accepted', false);
}
In this case, the listener to the accepting
event can return false
and $this->setAcceptedFlag()->save();
will not be triggered. I don't think we need this functionality right now.
Regarding tests... I must confess I have not done much testing in my projects so I think you will need to help me on this one as I don't know how to test it correctly.
Okay, I'll merge this changes, and we will return to tests a bit later this week. And release will be published only after tests will be ready.
@jonagoldman thank you for researching topics about this feature and compiling all this stuff down!
Fire events on actions. Related to https://github.com/cybercog/laravel-eloquent-flag/issues/4 and https://github.com/cybercog/laravel-eloquent-flag/issues/33. No tests added.