Download the PHP package nolanos/laravel-model-typescript-transfomer without Composer
On this page you can find all versions of the php package nolanos/laravel-model-typescript-transfomer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nolanos/laravel-model-typescript-transfomer
More information about nolanos/laravel-model-typescript-transfomer
Files in nolanos/laravel-model-typescript-transfomer
Package laravel-model-typescript-transfomer
Short Description Generate Typescript definitions for your Eloquent models
License MIT
Homepage https://github.com/nolanos/laravel-model-typescript-transfomer
Informations about the package laravel-model-typescript-transfomer
Laravel Model Typescript Transformer
This package generates TypeScript definitions for Laravel Eloquent models using spatie/laravel-typescript-transformer.
Installation
Install via Composer:
Update your config/typescript-transformer.php config file by...
- Appending
ModelTypeScriptCollectorto thecollectorsarray. - Appending
ModelTransformerto thetransformersarray.
Usage
Generate TypeScript definitions by running:
How it works
Identifying Properties
The ModelTransformer identifies the properties of the given Model by looking at the columns in the database table, and then
filters columns out based on the $hidden and $visible properties of the model.
Mapping Database Types to TypeScript Types
Property types are determined by mapping the database column type to a TypeScript type. The following mappings are used:
| Typescript Type | Database Type |
|---|---|
| string | uuid, string, text, varchar, character varying, date, datetime, timestamp, timestamp without time zone, bpchar, timestamptz, time, bytea, blob |
| number | integer, bigint, int2, int4, int8, float, double, decimal, float8, numeric |
| boolean | boolean, bool |
Note: Unknown column types will be mapped to unknown and are followed by a comment stating the db type.
Nullable Types
If a column is nullable, the TypeScript type will be suffixed with | null.
Example
Let's look at a simple of example of a user model in a PostgreSQL database.
The User model might look like this:
`
Will generate the following TypeScript definition:
Limitations
This package has some limitations.
Take a look at the issues to see what's missing.
Development
Setup
Running Tests
Publishing new Versions
To publish a new version of the package, you need to create a new tag and push it to the repository.
Go to Packagist and click on "Update" to update the package.
All versions of laravel-model-typescript-transfomer with dependencies
laravel/framework Version ^12.0|^13.0
spatie/laravel-typescript-transformer Version ^2.4