Skip to content

Commit

Permalink
Allowing class string in listener array. Renamed CreatingPersonEvent …
Browse files Browse the repository at this point in the history
…to PersonEvent to show that the listener class name is no longer required to begin with event type
  • Loading branch information
shooka committed Oct 21, 2015
1 parent 22282f5 commit b1fbfc4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ModelEventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ModelEventServiceProvider extends ServiceProvider
public function boot()
{
foreach ($this->listeners() as $model => $listeners) {
foreach ($listeners as $listener) {
foreach ((array)$listeners as $listener) {
$model::observe($listener);
}
}
Expand Down
7 changes: 3 additions & 4 deletions tests/support/ModelEventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
class ModelEventServiceProvider extends ServiceProvider
{
protected $listeners = [
Person::class => [
CreatingPersonEvent::class
]
Person::class => PersonEvent::class

];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Shooka\ModelEvents\ModelEvent;

class CreatingPersonEvent extends ModelEvent
class PersonEvent extends ModelEvent
{
public function creating(Person $person)
{
if(!$person->name) {
return false;
}
}
}
}

0 comments on commit b1fbfc4

Please sign in to comment.