tighten / parental

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

ADD support for enum-casting of `type` field #110

Closed marcoguido closed 1 year ago

marcoguido commented 1 year ago

With this PR, users will be able to make use of this trait also if the type column is casted to an Enum instance.

In one of my projects, for example, I have the following situation, where UserType is a backed enum holding possible values.

class User extends Authenticatable {
    protected $casts = [
        'type' => UserType::class,
    ];
}

When creating a new model instance Laravel resolves the cast providing the proper Enum instance, leading to an exception being thrown in classFromAlias where the $aliasOrClass is not a simple string, but the Enum instance.

lorenzolosa commented 1 year ago

I got in the same situation, I have made it work in my code in the same way, and I was thinking about submitting a PR exactly like this - so I'm happy to see that it's already there and I hope it will be merged.

marcoguido commented 1 year ago

I hope that too 😉

binaryfire commented 1 year ago

Any idea if/when this might be merged? Would love to switch from our custom solution to this package but we need Enum support too.

driftingly commented 1 year ago

@marcoguido @lorenzolosa @binaryfire Tagged at 1.3.4

Thanks @marcoguido 🙌