Download the PHP package salemc/typescriptify-laravel-models without Composer
On this page you can find all versions of the php package salemc/typescriptify-laravel-models. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download salemc/typescriptify-laravel-models
More information about salemc/typescriptify-laravel-models
Files in salemc/typescriptify-laravel-models
Package typescriptify-laravel-models
Short Description Convert Laravel models into TypeScript interfaces
License MIT
Informations about the package typescriptify-laravel-models
TypeScriptify Laravel Models
Effortlessly generate TypeScript interface definitions from Laravel Model classes.
Usage
The main invocation of php artisan typescriptify:model
with --help lists sub-commands available:
Example Usage
Invocating php artisan typescriptify:model \App\Models\User
on a fresh Laravel installation will produce:
Or if you prefer, you can instantiate your own version of the TypeScriptifyModel
class:
Relation Mapping
TypeScriptify Laravel Models supports belongsTo
relation mapping.
Imagine you have the following scenario:
With a foreign key (and a foreign key constraint) role_id
on the users
table.
It would be nice if instead of having a role_id: number
attribute on the generated User
interface, it was instead the full relational dataset, right? Well, TypeScriptify Laravel Models is able to recognise that the role_id
column should be the Role
model, and will map it to a reusable interface definition for you. Unfortunately, we're not able to determine the exact relation name; instead we attempt to guess it for you, based on the foreign key name:
How It Works
Database
TypeScriptify Laravel Models works primarily by gathering column data from the database your Laravel instance is setup with. Once gathered, it maps column types to known TypeScript types. This means if you don't have a database column for a property you want converted, it won't exist in the final TypeScript interface definition.
Casts
TypeScriptify Laravel Models also respects predictable Laravel casts (specifically protected $casts
and protected $dates
) you've setup in the model being converted. It will map all known casts to TypeScript types.
Caveats
TypeScriptify Laravel Models is only able to map predictable data types to TypeScript types. Custom Casts and Custom Accessors are not, and cannot be supported.
If TypeScriptify Laravel Models fails to map a type to a TypeScript type, it will set the value to unknown
in the TypeScript interface definition.
All versions of typescriptify-laravel-models with dependencies
doctrine/dbal Version ^3.4
illuminate/support Version ^9.36
illuminate/database Version ^9.36
illuminate/console Version ^9.36