Download the PHP package synergitech/laravel-magic-enums without Composer

On this page you can find all versions of the php package synergitech/laravel-magic-enums. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-magic-enums

JS Tests PHP Tests

Laravel Magic Enums

Have you ever wanted to reference your PHP enums in your frontend code but ended up (or didn't want to end up) duplicating them manually? Well here is your answer.

Installing

You need both sides to get started.

Getting Started

  1. Add the trait and interface from this package to your enums

  2. Include the route somewhere in your routes file of choice, in this example we are going to create /api/enums.

You can obviously include middleware on it if you wish, e.g. for an authenticated session, but this may affect your frontend's ability to initialise, so please be careful.

We recommend you don't include sensitive information in your enums.

  1. We work primarily with Inertia and Vue so the integration looks something like this. Note the use of async/await and reusing the route we created earlier.

  2. During development, you can have Vite reload automatically when your enums change. This is handled by chokidar. You might also wish to compile a types definition so your IDE knows the details of the enums. We recommend adding this file to your .gitignore file.

While not necessary, you can also provide a cli command to prettierCommand to format the generated TypeScript file according to your project's standards.

Update your vite.config.js as follows. You'll notice we provide both the directory and the endpoint.

  1. Now in your frontend, you can reference your enums as if they were key-value objects.

Advanced Usage

Sub Enums

You may choose to have an array within your enum of a subset of the values for a specific purpose or grouping.

If you use the PHP attribute SynergiTech\MagicEnums\Attributes\AppendConstToMagic, then an extra enum representing this will be available in the frontend.

You may also have an array which maps some or all of the values of the enum to a different string.

If you use the PHP attribute SynergiTech\MagicEnums\Attributes\AppendValueToMagic, then an extra enum representing this will be available in the frontend.

For example:

Will create the output:

Cache and Versioning

To avoid rebuilding the json everytime the endpoint is requested, you can add a file named VERSION to your root folder. Magic Enums will determine whether to cache the output based on the time this file was last touched. You can specify a custom cache key in the config.

Extending

If you wish to have more control over appending values to your magic enums for the frontend, you can extend the current trait using something along the lines of app/Traits/CustomMagic.php as long as you always follow the interface and provide the function.


All versions of laravel-magic-enums with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version >=9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package synergitech/laravel-magic-enums contains the following files

Loading the files please wait ....