Skip to content

Commit

Permalink
Merge pull request #61 from BertvanHoekelen/fix-observer-on-self-refe…
Browse files Browse the repository at this point in the history
…rencing-parent

[bugfix] Only register observer for child classes
  • Loading branch information
calebporzio authored Dec 28, 2019
2 parents d2be97f + c36aa84 commit d942b89
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/HasChildren.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ protected static function registerModelEvent($event, $callback)
// from the child's boot method as well.
if (! self::parentIsBooting()) {
foreach ((new self)->childTypes as $childClass) {
$childClass::registerModelEvent($event, $callback);
if ($childClass !== self::class) {
$childClass::registerModelEvent($event, $callback);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Models/Vehicle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class Vehicle extends Model
];

protected $childTypes = [
'car' => Car::class
'car' => Car::class,
'truck' => self::class,
];

protected $guarded = [];
Expand Down

0 comments on commit d942b89

Please sign in to comment.