PHPackages                             juanparati/model2ts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. juanparati/model2ts

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

juanparati/model2ts
===================

An artisan command that can generate Typescript interfaces from Eloquent models.

1.0(5y ago)022MITPHPPHP &gt;=7.3

Since Oct 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/juanparati/model2ts)[ Packagist](https://packagist.org/packages/juanparati/model2ts)[ RSS](/packages/juanparati-model2ts/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

Model2Ts
========

[](#model2ts)

What is it?
-----------

[](#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
------------

[](#installation)

```
    composer require juanparati/model2ts --dev

```

Usage
-----

[](#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
-------------------------

[](#accessors-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
------------------------

[](#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.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2018d ago

Major Versions

0.9 → 1.02020-10-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/4caf72b4d969cfb8cdfbdc1d594c85b51c9316caf76b80aa0f9de7e3736cf59f?d=identicon)[juanparati](/maintainers/juanparati)

---

Tags

interfaceslaravelhelpergeneratortypescriptmodels

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/juanparati-model2ts/health.svg)

```
[![Health](https://phpackages.com/badges/juanparati-model2ts/health.svg)](https://phpackages.com/packages/juanparati-model2ts)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M683](/packages/barryvdh-laravel-ide-helper)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
