PHP code example of crazybooot / laravel-constants-to-js

1. Go to this page and download the library: Download crazybooot/laravel-constants-to-js 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/ */

    

crazybooot / laravel-constants-to-js example snippets


return [
    'constants' => [
        'user' => [
            'type' => [
                'class' => App\User::class,
            ],
        ],
    ],
];

return [
    'constants' => [
        'queue' => [
            'connections' => [
                'config' => 'queue.connections',
            ],
        ],
    ],
];

return [
    'constants' => [
        'user' => [
            'type'   => [
                'class'       => App\User::class,
                'starts_with' => 'TYPE_',
            ],
            'status' => [
                'class'       => App\User::class,
                'starts_with' => 'STATUS_',  
            ],
        ],
    ],
];

return [
    'constants' => [
        'user' => [
            'type'   => [
                'class'       => App\User::class,
                'transform_key' => [
                    'strtoupper' => [],
                ]
            ],
        ],
        'queue' => [
            'connections' => [
                'config' => 'queue.connections',
                'transform_value' => [
                    'array_get'  => ['driver'],
                    'title_case' => []
                ],
            ],
        ],
    ],
];

return [
    'target_path' => resource_path('assets/js/constants.js'),
];
bash
php artisan vendor:publish --provider="Crazybooot\ConstantsToJs\Providers\ServiceProvider" --tag=config
 bash
php artisan constants:js