tighten / parental

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

Use getChildTypes method to allow method overriding #53

Closed BertvanHoekelen closed 5 years ago

BertvanHoekelen commented 5 years ago

We define our child types based on values from phpenum, however all constants are marked as private and cannot be used outside of the enum (this enforces us the use the method instead of the private constant).

But expressions are not allowed as field default values, so we would like to override the getChildTypes method.

e.g.

...

class Vehicle extends Model
{
    use HasChildren;

   protected $childTypes = [
        EnumVehicle::CAR => Car::class
   ];
}

Becomes in our case e.g.

...

class Vehicle extends Model
{
    use HasChildren;

    public function getChildTypes(): array
    {
          return [
              EnumVehicle::CAR()->getValue() => Car::class
          ];
    }
}