Adds transformation support for bensampo/laravel-enum based enums to the spatie/laravel-typescript-transformer package.
composer require wthealth/laravel-enum-transformer
Add the following Transformer
to the configuration config/type-script-transformer
'transformers' => [
Webtools\LaravelEnumTransformer\LaravelEnumTransformer::class,
],
Now any enum created based on BenSampo\Enum\Enum
can be transformed to typescript like below
final class UserType extends Enum
{
const Administrator = 0;
const Moderator = 1;
const Subscriber = 2;
const SuperAdministrator = 3;
}
export type UserType = {
Administrator = 0,
Moderator = 1,
Subscriber = 2,
SuperAdministrator = 3,
}
Or transform to enums:
This must be enabled in config/type-script-transformer
'transform_to_native_enums' => true,
export enum UserType {
Administrator = 0,
Moderator = 1,
Subscriber = 2,
SuperAdministrator = 3,
}
Read the documentation for further details.
The MIT License (MIT). Please see License File for more information.