PHPackages                             salemc/typescriptify-laravel-models - 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. salemc/typescriptify-laravel-models

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

salemc/typescriptify-laravel-models
===================================

Convert Laravel models into TypeScript interfaces

1.0.0(3y ago)23[3 issues](https://github.com/SalemC/typescriptify-laravel-models/issues)MITPHPPHP &gt;=8.1

Since Oct 18Pushed 3y ago1 watchersCompare

[ Source](https://github.com/SalemC/typescriptify-laravel-models)[ Packagist](https://packagist.org/packages/salemc/typescriptify-laravel-models)[ RSS](/packages/salemc-typescriptify-laravel-models/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

TypeScriptify Laravel Models
============================

[](#typescriptify-laravel-models)

Effortlessly generate TypeScript interface definitions from Laravel Model classes.

Usage
-----

[](#usage)

The main invocation of `php artisan typescriptify:model` with --help lists sub-commands available:

```
php artisan typescriptify:model --help

Description:
  Convert a model to it's TypeScript definition.

Usage:
  typescriptify:model [options] [--]

Arguments:
  model The fully qualified class name for the model - e.g. App\Models\User

Options:
      --includeHidden[=INCLUDEHIDDEN] Include the protected $hidden properties [default: "false"]
      --includeRelations[=INCLUDERELATIONS] Map foreign key columns to interface definitions [default: "true"]

```

Example Usage
-------------

[](#example-usage)

Invocating `php artisan typescriptify:model \App\Models\User` on a fresh Laravel installation will produce:

```
interface User {
    id: number;
    name: string;
    email: string;
    email_verified_at: string|null;
    created_at: string|null;
    updated_at: string|null;
}
```

Or if you prefer, you can instantiate your own version of the `TypeScriptifyModel` class:

```
use SalemC\TypeScriptifyLaravelModels\TypeScriptifyModel;

echo (new TypeScriptifyModel(\App\Models\User::class))->generate();
```

Relation Mapping
----------------

[](#relation-mapping)

**TypeScriptify Laravel Models** supports `belongsTo` relation mapping.

Imagine you have the following scenario:

```
// app/Models/User.php
// columns: id, name, email, password, role_id

public function role(): BelongsTo {
    return $this->belongsTo(Role::class);
}

// app/Models/Role.php
// columns: id, name

public function users(): HasMany {
    return $this->hasMany(User::class);
}
```

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:

```
// Automatically generated Role interface.
interface Role {
    id: number;
    name: string;
}

interface User {
    id: number;
    name: string;
    email: string;
    password: string;
    role: Role; // 'guessed' attribute name of 'role' (from 'role_id') with the interface Role, generated above.
}
```

How It Works
------------

[](#how-it-works)

### Database

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

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

[](#caveats)

**TypeScriptify Laravel Models** is only able to map *predictable* data types to TypeScript types. [Custom Casts](https://laravel.com/docs/9.x/eloquent-mutators#custom-Casts) and [Custom Accessors](https://laravel.com/docs/9.x/eloquent-mutators#accessors-and-mutators) 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.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

1299d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1b634618282435dc95cf1dc7f785549bd72007393fddc83a3a5732dc13b261d9?d=identicon)[Salem](/maintainers/Salem)

---

Top Contributors

[![SalemC](https://avatars.githubusercontent.com/u/32452313?v=4)](https://github.com/SalemC "SalemC (56 commits)")

---

Tags

laravellaravel-modelstypescript-conversion

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/salemc-typescriptify-laravel-models/health.svg)

```
[![Health](https://phpackages.com/badges/salemc-typescriptify-laravel-models/health.svg)](https://phpackages.com/packages/salemc-typescriptify-laravel-models)
```

###  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)[orchestra/canvas

Code Generators for Laravel Applications and Packages

21017.2M157](/packages/orchestra-canvas)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[zonneplan/laravel-module-loader

Module loader for Laravel

24118.4k](/packages/zonneplan-laravel-module-loader)[tehwave/laravel-achievements

Simple, elegant Achievements the Laravel way

7012.8k](/packages/tehwave-laravel-achievements)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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