Download the PHP package scrumble-nl/laravel-model-ts-type without Composer
On this page you can find all versions of the php package scrumble-nl/laravel-model-ts-type. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download scrumble-nl/laravel-model-ts-type
More information about scrumble-nl/laravel-model-ts-type
Files in scrumble-nl/laravel-model-ts-type
Package laravel-model-ts-type
Short Description This package makes it possible to generate TypeScript types based on your models
License MIT
Homepage https://github.com/scrumble-nl/laravel-model-ts-type
Informations about the package laravel-model-ts-type
laravel-model-ts-type
Generate TypeScript types based on your models.
Usage
Installation
Install the package using composer:
Generating types
Additional options:
Option | Default value | Description |
---|---|---|
modelDir |
app/Models |
The root directory where the package can find all Laravel models |
outputDir |
resources/js/models |
The root directory for outputting the .d.ts files |
namespace |
false |
The namespace of the generated Types. Use false if you don't prefer to have one |
noKebabCase |
false |
Whether the file name should be formatted to kebab case |
model |
null |
Choose to generate a model for a specific file. For example you can use App\Models\User |
indentationSpaces |
4 |
The amount of spaces used for indentation |
If you want to change the default values you can publish the config file and change it to you liking.
NOTE: Do not forget to add the directory to your typeroots in tsconfig.json
What does it do?
This package takes (almost) all off Laravel's magic into account. It follows these steps for generating a Type:
- Retrieve all fields from te database (only MySQL/MariaDB supported) and map them to default types (string, number, etc.)
- Add relations for the Model, they will point to the related generated Type
- Add the attribute getters for the Model
- Check the
casts
attribute - Remove all fields that are in the
hidden
attribute
Example output
Roadmap
- [x] Add tests (in progress)
- [ ] Generate types for packagized models
- [x] Create command to generate type for 1 model
- [ ] Implement unqualified name for relation doc blocks
Contributing
If you would like to see additions/changes to this package you are always welcome to add some code or improve it.
Scrumble
This product has been originally developed by Scrumble for internal use. As we have been using lots of open source packages we wanted to give back to the community. We hope this helps you getting forward as much as other people helped us!
All versions of laravel-model-ts-type with dependencies
ext-pdo Version *
laravel/framework Version ^10.0|^11.0
laravel/helpers Version ^1.6