Skip to content

Commit

Permalink
Added ability to listen for model events directly on the model instance
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Feb 10, 2020
1 parent cb8da53 commit 840fc27
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Models/Concerns/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LdapRecord\Models\Concerns;

use LdapRecord\Container;
use Closure;
use LdapRecord\Models\Events\Event;

trait HasEvents
Expand All @@ -16,6 +16,19 @@ trait HasEvents
*/
protected function fireModelEvent(Event $event)
{
return Container::getEventDispatcher()->fire($event);
return static::getConnectionContainer()->getEventDispatcher()->fire($event);
}

/**
* Listens to a model event.
*
* @param string $event
* @param Closure $listener
*
* @return mixed
*/
protected function listenForModelEvent($event, Closure $listener)
{
return static::getConnectionContainer()->getEventDispatcher()->listen($event, $listener);
}
}

0 comments on commit 840fc27

Please sign in to comment.