LaravelPackages.net
Acme Inc.
Toggle sidebar
wthealth/laravel-enum-transformer

84.626
2
1.1.1
About wthealth/laravel-enum-transformer

wthealth/laravel-enum-transformer is a Laravel package. It currently has 2 GitHub stars and 84.626 downloads on Packagist (latest version 1.1.1). Install it with composer require wthealth/laravel-enum-transformer. Discover more Laravel packages by wthealth or browse all Laravel packages to compare alternatives.

Last updated

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.

Comments