Download the PHP package juanparati/model2ts without Composer
On this page you can find all versions of the php package juanparati/model2ts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download juanparati/model2ts
More information about juanparati/model2ts
Files in juanparati/model2ts
Package model2ts
Short Description An artisan command that can generate Typescript interfaces from Eloquent models.
License MIT
Informations about the package model2ts
Model2Ts
What is it?
An artisan command that translates Eloquent models into Typescript interfaces.
Model2Ts checks the model structure using reflection techniques, and the related table structure in order to properly infer the correct types.
Installation
composer require juanparati/model2ts --dev
Usage
Generate Typescript interface for a specific model:
artisan model2ts:generate "App\Models\User" user.ts
The following parameters can change the behaviour of the command:
--ignore-hidden : Discard attributes registered in $hidden property
--ignore-casts : Do not use $casts property in order to infer the attributes types
--ignore-appends : Do not include virtual accessor located in $appends property
--ignore-accessors : Do not infer types from model accessors.
Accessor's type inference
Model2Ts can infer from the native accessors and also from the virtual ones registered in the $appends property.
In order to make it work the type inference is require to define a return type in each of the accessor methods.
Example:
public function getFirstnameAttribute() : string {
return explode(' ', $this->attributes['name'])[0];
}
Data structure inference
Some database types is difficult to infer the type of some attributes, because it may be used in order to store structure data. This is the case of blob and text fields. In this case the interface file will contain a comment indicating that field may be content a structure type like an object or an array.
All versions of model2ts with dependencies
illuminate/database Version ^7 || ^8
illuminate/console Version ^6 || ^7 || ^8
illuminate/filesystem Version ^6 || ^7 || ^8
illuminate/support Version ^6 || ^7 || ^8
doctrine/dbal Version ~2.3