Skip to content

Commit

Permalink
feat: working state merging fillable traits
Browse files Browse the repository at this point in the history
  • Loading branch information
gcavanunez committed Nov 7, 2023
1 parent a4d4899 commit b023d60
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/HasParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getMorphClass(): string

return (new $parentClass)->getMorphClass();
}

/**
* Get the class name for poly-type collections
*
Expand All @@ -140,4 +140,28 @@ protected function getParentClass(): string

return $parentClassName ?: $parentClassName = (new ReflectionClass($this))->getParentClass()->getName();
}


/**
* Merge the fillable attributes for the model with Parent Class
*
* @return array<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) {
return $this->fillable;
}
}
}

0 comments on commit b023d60

Please sign in to comment.