jefhar/laravel-export-constants

Export your PHP class constants to JavaScript

v0.1.0 2022-04-30 01:35 UTC

This package is auto-updated.

Last update: 2024-04-12 21:15:30 UTC


README

Requires Laravel ^9.0 and PHP ^8.0

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Latest Version on Packagist Total Downloads

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.