diff --git a/src/HasParent.php b/src/HasParent.php index 860cf00..da5fa09 100644 --- a/src/HasParent.php +++ b/src/HasParent.php @@ -143,18 +143,20 @@ protected function getParentClass(): string /** - * Merge the fillable attributes for the model with Parent Class + * Merge the fillable attributes for the model with those of its Parent Class * * @return array */ public function getFillable() { - $parentClass = $this->getParentClass(); + if ((new ReflectionClass($parentClass))->isAbstract()) { + return $this->fillable; } $parentFillable = (new $parentClass)->getFillable(); + return array_unique(array_merge($parentFillable, $this->fillable)); } } diff --git a/tests/Features/ChildModelFillablesMergeWithParentModelFillablesTest.php b/tests/Features/ChildModelFillablesMergeWithParentModelFillablesTest.php index 8eff61b..c2a3584 100644 --- a/tests/Features/ChildModelFillablesMergeWithParentModelFillablesTest.php +++ b/tests/Features/ChildModelFillablesMergeWithParentModelFillablesTest.php @@ -16,7 +16,9 @@ function child_fillables_are_merged_with_parent_fillables() 'industry' => 'Technology', 'skill_level' => 'Advanced', ]); + $event = Event::first(); + $this->assertEquals($event->name, $workshop->name); } } diff --git a/tests/Models/Conference.php b/tests/Models/Conference.php index 8837843..c7d3c42 100644 --- a/tests/Models/Conference.php +++ b/tests/Models/Conference.php @@ -7,5 +7,6 @@ class Conference extends Event { use HasParent; + protected $fillable = ['industry']; } diff --git a/tests/Models/Event.php b/tests/Models/Event.php index b4ec4fd..5ad0d16 100644 --- a/tests/Models/Event.php +++ b/tests/Models/Event.php @@ -6,7 +6,5 @@ class Event extends Model { - protected $fillable = [ - 'name', 'type' - ]; + protected $fillable = ['name', 'type']; } diff --git a/tests/Models/Workshop.php b/tests/Models/Workshop.php index 041a01e..c3d0c17 100644 --- a/tests/Models/Workshop.php +++ b/tests/Models/Workshop.php @@ -7,5 +7,6 @@ class Workshop extends Event { use HasParent; + protected $fillable = ['industry', 'skill_level']; }