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 jeff@jeffharris.us 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.