Skip to content

Latest commit

 

History

History
70 lines (53 loc) · 2.08 KB

README.md

File metadata and controls

70 lines (53 loc) · 2.08 KB

Laravel Enum Transformer

CI Action Scrutinizer Code Quality Code Coverage

Adds transformation support for bensampo/laravel-enum based enums to the spatie/laravel-typescript-transformer package.

Installation & Configuration

 composer require wthealth/laravel-enum-transformer

Add the following Transformer to the configuration config/type-script-transformer

'transformers' => [
    Webtools\LaravelEnumTransformer\LaravelEnumTransformer::class,
],

Usage

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.

License

The MIT License (MIT). Please see License File for more information.