tighten / parental

Use single table inheritance in your Laravel app
MIT License
1.36k stars 98 forks source link

[Feature request] Merge fillable columns with parent #118

Closed timyourivh closed 9 months ago

timyourivh commented 1 year ago

I was missing this feature and stumbled upon this issue: #77

After reading the issue and the comments I decided to create this feature request and introduce a potential way of implementing this.

This would be nice feature to have.

I've created a trait in my project based off of @litvinjuan's answer in the issue:

<?php

namespace App\Concerns;

trait ExtendParentFillables
{
    public function getFillable()
    {
        $parentFillable = (new \ReflectionClass($this))->getParentClass()->newInstance()->getFillable();

        return array_merge($this->fillable, $parentFillable);
    }
}

This could be included in the package and to prevent breaking changes this could be added in the form of a trait as well. Which would make it opt-in and opens the potential for a "guarded" form as well.

The trait is not only useful in parental's context as it can be used to extend any models' fillables.

driftingly commented 9 months ago

Resolved by #120