diff --git a/src/HasParent.php b/src/HasParent.php index 0019116..860cf00 100644 --- a/src/HasParent.php +++ b/src/HasParent.php @@ -149,19 +149,12 @@ protected function getParentClass(): string */ public function getFillable() { - // @todo currently failing when parent class is abstract - // $parentFillable = (new \ReflectionClass((new \ReflectionClass($this))->getParentClass())); - // if ($parentFillable->isAbstract()) { - // return ['*']; - // } - - try { - $parentClass = $this->getParentClass(); - $parentFillable = (new $parentClass)->getFillable(); - $arr = array_unique(array_merge($parentFillable, $this->fillable)); - return $arr; - } catch (\Throwable $th) { + + $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 new file mode 100644 index 0000000..8eff61b --- /dev/null +++ b/tests/Features/ChildModelFillablesMergeWithParentModelFillablesTest.php @@ -0,0 +1,22 @@ + 'Scaling Laravel', + '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 new file mode 100644 index 0000000..8837843 --- /dev/null +++ b/tests/Models/Conference.php @@ -0,0 +1,11 @@ +string('type')->nullable(); $table->timestamps(); }); + + Schema::create('events', function ($table) { + $table->increments('id'); + $table->string('type')->nullable(); + $table->string('name'); + $table->string('industry')->nullable(); + $table->string('skill_level')->nullable(); + $table->timestamps(); + }); } }