Download the PHP package gigerit/laravel-morphmap-js-generator without Composer
On this page you can find all versions of the php package gigerit/laravel-morphmap-js-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gigerit/laravel-morphmap-js-generator
More information about gigerit/laravel-morphmap-js-generator
Files in gigerit/laravel-morphmap-js-generator
Package laravel-morphmap-js-generator
Short Description Generate frontend JavaScript/TypeScript constants from Laravel morph map configuration
License MIT
Informations about the package laravel-morphmap-js-generator
Laravel Morph Map JS Generator
Generate frontend JavaScript/TypeScript constants from your Laravel application's morph map configuration. Keep your frontend morph types in sync with your Laravel models automatically.
Installation
You can install the package via composer:
The package will automatically register itself with Laravel.
Usage
After installation, you can generate the JavaScript/TypeScript constants using the artisan command:
Example
If your Laravel application has this morph map configuration:
With --ts, the command generates these TypeScript constants:
Without --ts, the command writes morphMap.js with the same runtime exports
(MORPH_MAP, MORPH_MAP_MODELS, and getMorphMapModel) as executable JavaScript,
without TypeScript annotations or the MorphMapValue type export.
The helper accepts morph values such as 'user' or 1. Constant names such as
'USER' are only valid arguments if they are also morph values. Untyped callers
passing an unknown value retain the 'Unknown' runtime fallback.
Using in Your Frontend
Features
- 🔄 Automatically syncs with Laravel's morph map configuration
- 📝 Generates JavaScript or TypeScript files
- 🎯 Type-safe with TypeScript support
- 🔍 Includes helper function for model name lookup
- 🎨 Converts numeric keys to readable constant names
- 📦 Zero configuration required
- 💻 Command output shows current mappings
Command Options
| Option | Description | Default |
|---|---|---|
--ts |
Generate TypeScript instead of JavaScript | false |
--path |
Custom output path for generated file | resources/js |
Best Practices
- Version Control: Add the generated file to your version control system to track changes.
-
Build Process: Include the generation command in your build process to ensure sync:
- Type Safety: Use TypeScript for better type checking and IDE support.
Development
Install PHP dependencies with composer install and the test compiler with
npm ci, then run npm test. The tests boot the package service provider,
execute morphmap:generate-js with and without --ts, parse and execute the
generated JavaScript without Node type stripping, and compile and execute the
generated TypeScript under strict settings. Both paths verify lookups and the
runtime fallback. See the test workflow for the
tested PHP and Laravel versions.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.