PHP code example of intrfce / laravel-frontend-enums

1. Go to this page and download the library: Download intrfce/laravel-frontend-enums 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/ */

    

intrfce / laravel-frontend-enums example snippets


use Intrfce\LaravelFrontendEnums\Attributes\PublishEnum;

#[PublishEnum]
enum MyEnum: string {
    case Foo = 'foo';
    case Bar = 'bar';
}

// config/laravel-frontend-enums.php
return [
    
    // Customise the output directory.
    'publish_to' => resource_path('js/Enums'),
    
    // Customise the folders scanned for enum classes
    'discover_in' => [
        app_path(),
    ],
    
    // Always output as typescript enums.
    'as_typescript' => true,
    
];

'discover_in' => [
    app_path(),
    base_path('app-modules/*/src'),
],

'as_typescript' => true,

#[PublishEnum(asTypescript: true)]  // Force TypeScript for this enum
#[PublishEnum(asTypescript: false)] // Force JavaScript for this enum
#[PublishEnum]                      // Follow the global config setting

npm install -D vite-plugin-watch
bash
php artisan publish:enums-to-javascript
bash
php artisan vendor:publish --tag=config --provider="Intrfce\LaravelFrontendEnums\LaravelFrontendEnumsServiceProvider"