PHPackages                             jefhar/laravel-export-constants - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jefhar/laravel-export-constants

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jefhar/laravel-export-constants
===============================

Export your PHP class constants to JavaScript

v0.1.0(4y ago)05MITPHPPHP ^8.0

Since Apr 30Pushed 2y ago1 watchersCompare

[ Source](https://github.com/jefhar/laravel-export-constants)[ Packagist](https://packagist.org/packages/jefhar/laravel-export-constants)[ Docs](https://github.com/jefhar/laravel-export-constants)[ RSS](/packages/jefhar-laravel-export-constants/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

Duplicate PHP Constants in JavaScript
=====================================

[](#duplicate-php-constants-in-javascript)

Requires Laravel ^9.0 and PHP ^8.0

[![Latest Stable Version](https://camo.githubusercontent.com/238fe71fca8fbb59fba55100350cdbf0a14a90efc573cf5a8821cdc8bcf32255/687474703a2f2f706f7365722e707567782e6f72672f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732f76)](https://packagist.org/packages/jefhar/laravel-export-constants)[![Total Downloads](https://camo.githubusercontent.com/f230b6cf01c8bc7b95bf99e6b9f09015fdba135c0a1e7cc57ce6f8286dd4126c/687474703a2f2f706f7365722e707567782e6f72672f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732f646f776e6c6f616473)](https://packagist.org/packages/jefhar/laravel-export-constants)[![Latest Unstable Version](https://camo.githubusercontent.com/caf88bb32c0d7778e19ed801d723efd0146a9bb06aa2faee09cf438b850aac9b/687474703a2f2f706f7365722e707567782e6f72672f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732f762f756e737461626c65)](https://packagist.org/packages/jefhar/laravel-export-constants)[![License](https://camo.githubusercontent.com/17d49491c8cced03a493fbc864d963552f16cd1d8331ca36d2b7423e39e9caef/687474703a2f2f706f7365722e707567782e6f72672f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732f6c6963656e7365)](https://packagist.org/packages/jefhar/laravel-export-constants)[![PHP Version Require](https://camo.githubusercontent.com/147d4ffc1566f366fbda3fba699e95c60a33ff3333b4404e1cd1ef0407a526d0/687474703a2f2f706f7365722e707567782e6f72672f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732f726571756972652f706870)](https://packagist.org/packages/jefhar/laravel-export-constants)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b6f4fcd2955b4e2fc544e2ff91df34360e536002308477292ddb61921008e697/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jefhar/laravel-export-constants)[![Total Downloads](https://camo.githubusercontent.com/f6c2657529a258db921b3adb2074bb44a69007bd0625ede8ed8992405afaebd9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a65666861722f6c61726176656c2d6578706f72742d636f6e7374616e74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jefhar/laravel-export-constants)

Like you, I hate bare strings and magic numbers in code, so we use PHP constants. With the magic of [Attributes](https://www.php.net/manual/en/language.attributes.overview.php), your PHP constants can be duplicated for use in your Vue, React, and POJS

Installation
------------

[](#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
-----

[](#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

```
