PHP code example of toniel / laravel-enum-to-typescript
1. Go to this page and download the library: Download toniel/laravel-enum-to-typescript library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
toniel / laravel-enum-to-typescript example snippets
// config/enum-to-typescript.php
return [
// The directory where your PHP enums are located.
'source_dir' => 'app/Enums',
// The directory where the generated TypeScript enums will be placed.
'dest_dir' => 'resources/ts/Enums',
// The case for the generated TypeScript enum filenames.
// Supported values: "PascalCase", "kebab-case".
'filename_case' => 'PascalCase',
// Defines how the TypeScript enums are generated.
// Supported values: "multiple_files", "single_file".
'output_strategy' => 'multiple_files',
// When using the "single_file" output strategy, this will be the name
// of the generated TypeScript file (without the .ts extension).
'single_file_name' => 'enums',
];
// app/Enums/UserRole.php
namespace App\Enums;
enum UserRole: string
{
case ADMIN = 'admin';
case USER = 'user';
}