PHPackages                             isgarrido/laravel-model-typescript-transfomer - 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. [Database &amp; ORM](/categories/database)
4. /
5. isgarrido/laravel-model-typescript-transfomer

ActiveLibrary[Database &amp; ORM](/categories/database)

isgarrido/laravel-model-typescript-transfomer
=============================================

Generate Typescript definitions for your Eloquent models

v1.4(9mo ago)05MITPHPPHP ^8.2CI failing

Since Sep 5Pushed 9mo agoCompare

[ Source](https://github.com/IsGarrido/laravel-model-typescript-transfomer)[ Packagist](https://packagist.org/packages/isgarrido/laravel-model-typescript-transfomer)[ Docs](https://github.com/isgarrido/laravel-model-typescript-transfomer)[ GitHub Sponsors](https://github.com/sponsors/ncphillips)[ RSS](/packages/isgarrido-laravel-model-typescript-transfomer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (7)Used By (0)

Laravel Model Typescript Transformer
====================================

[](#laravel-model-typescript-transformer)

This package generates TypeScript definitions for Laravel Eloquent models using [spatie/laravel-typescript-transformer](https://github.com/spatie/laravel-typescript-transformer).

Installation
------------

[](#installation)

Install via Composer:

```
composer require isgarrido/laravel-model-typescript-transformer
```

Update your `config/typescript-transformer.php` config file by...

- Appending `ModelTypeScriptCollector` to the `collectors` array.
- Appending `ModelTransformer` to the `transformers` array.

```
    'collectors' => [
        // ...
        IsGarrido\LaravelModelTypescriptTransformer\ModelTypeScriptCollector::class,
    ],
    'transformers' => [
        // Etc....
        IsGarrido\LaravelModelTypescriptTransformer\ModelTransformer::class,
    ],
```

### Type Mapping Configuration

[](#type-mapping-configuration)

This package uses the type mapping defined in the `spatie/laravel-typescript-transformer` config file (`config/typescript-transformer.php`). Specifically, it looks for the `default_type_replacements` array to determine how PHP/DB types are mapped to TypeScript types.

For example:

```
'default_type_replacements' => [
    DateTime::class => 'string',
    DateTimeImmutable::class => 'string',
    Carbon\CarbonInterface::class => 'string',
    Carbon\CarbonImmutable::class => 'string',
    Carbon\Carbon::class => 'string',
    'tinyint' => 'number',
    'smallint' => 'number',
    'mediumint' => 'number',
    'int' => 'number',
    'bigint' => 'number',
    'integer' => 'number',
    'float' => 'number',
    'double' => 'number',
    'decimal' => 'number',
],
```

If a type or cast is found in this array, it will be used for the TypeScript definition. If not, the package falls back to its built-in mapping or uses `unknown /* type */` as a fallback.

You can customize type replacements by editing the `default_type_replacements` array in your config file.

Usage
-----

[](#usage)

Generate TypeScript definitions by running:

```
php artisan typescript:generate
```

How it works
------------

[](#how-it-works)

### Identifying Properties

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

[](#mapping-database-types-to-typescript-types)

Property types are determined by first checking the `default_type_replacements` config. If no mapping is found, the following built-in mappings are used:

Typescript TypeDatabase Typestringuuid, string, text, varchar, character varying, date, datetime, timestamp, timestamp without time zone, bpchar, timestamptz, time, bytea, blobnumberinteger, bigint, int2, int4, int8, float, double, decimal, float8, numericbooleanboolean, boolNote: Unknown column types will be mapped to `unknown` and are followed by a comment stating the db type. You can override this behavior by adding your own mapping to the config file.

### Nullable Types

[](#nullable-types)

If a column is nullable, the TypeScript type will be suffixed with `| null`.

Example
-------

[](#example)

Let's look at a simple of example of a user model in a PostgreSQL database.

```
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL ,
    password VARCHAR(255),
    active BOOLEAN NOT NULL,
    created_at TIMESTAMP,
    updated_at TIMESTAMP
);
```

The `User` model might look like this:

```
class User extends Model
{
    protected $hidden = ['password'];
}
```

Will generate the following TypeScript definition:

```
declare namespace App.Models {
  export interface User {
    id: number
    name: string
    email: string
    active: boolean
    created_at: string | null
    updated_at: string | null
  }
}
```

Limitations
-----------

[](#limitations)

This package has some limitations.

Take a look at the [issues](https://github.com/isgarrido/laravel-model-typescript-transfomer/issues) to see what's missing.

Development
===========

[](#development)

### Setup

[](#setup)

```
git clone git@github.com:isgarrido/laravel-model-typescript-transfomer.git

cd laravel-model-typescript-transformer

composer install
```

### Running Tests

[](#running-tests)

```
composer test
```

### Publishing new Versions

[](#publishing-new-versions)

To publish a new version of the package, you need to create a new tag and push it to the repository.

```
git tag vx.x.x
git push origin vx.x.x
```

Go to [Packagist](https://packagist.org/packages/isgarrido/laravel-model-typescript-transformer) and click on "Update" to update the package.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance57

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.7% 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

Every ~66 days

Total

6

Last Release

282d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d644e7eed5bbf497ab06e1daf28b1279c7e81ba486a46b0d2e50dbde4243ea08?d=identicon)[IsGarrido](/maintainers/IsGarrido)

---

Top Contributors

[![ncphillips](https://avatars.githubusercontent.com/u/824015?v=4)](https://github.com/ncphillips "ncphillips (22 commits)")[![IsGarrido](https://avatars.githubusercontent.com/u/9149500?v=4)](https://github.com/IsGarrido "IsGarrido (1 commits)")

---

Tags

laraveleloquenttypescript

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/isgarrido-laravel-model-typescript-transfomer/health.svg)

```
[![Health](https://phpackages.com/badges/isgarrido-laravel-model-typescript-transfomer/health.svg)](https://phpackages.com/packages/isgarrido-laravel-model-typescript-transfomer)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)[mozex/laravel-scout-bulk-actions

A Laravel Scout extension for bulk importing and flushing of all models.

1033.4k](/packages/mozex-laravel-scout-bulk-actions)

PHPackages © 2026

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