Export your PHP class constants to JavaScript
jefhar/laravel-export-constants is a Laravel package for export your php class constants to javascript.
It currently has 0 GitHub stars and 5 downloads on Packagist (latest version v0.1.0).
Install it with composer require jefhar/laravel-export-constants.
Discover more Laravel packages by jefhar
or browse all Laravel packages to compare alternatives.
Last updated
Requires Laravel ^9.0 and PHP ^8.0
Like you, I hate bare strings and magic numbers in code, so we use PHP constants. With the magic of Attributes, your PHP constants can be duplicated for use in your Vue, React, and POJS
You can install the package via composer:
composer require jefhar/laravel-export-constants
Copy the package config to your local config with the publish command:
php artisan vendor:publish --tag=export-constants-config
Add the attribute #[\LaravelExportConstants\Attributes\ExportToJs] to your public
constants and add the blade directive @constants to your app.blade.php file. Use
your PHP constant as normal, and look for your JavaScript constant under the
CONSTANTS global constant
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class NunyaController extends Controller
{
#[LaravelExportConstants\Attributes\ExportToJs]
public const URL_INDEX = 'nunya.index';
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
//
}
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.