jefhar / laravel-export-constants
Export your PHP class constants to JavaScript
Requires
- php: ^8.0
- haydenpierce/class-finder: ^0.4.3
- illuminate/support: ^9.0
Requires (Dev)
- orchestra/testbench: ^7.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-03-12 23:34:37 UTC
README
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
Installation
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
Usage
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) { // } }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email jeff@jeffharris.us instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.