PHPackages                             hemilrajput/laravel-typegen - 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. hemilrajput/laravel-typegen

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

hemilrajput/laravel-typegen
===========================

Generate TypeScript types from Eloquent models, Enums &amp; FormRequests.

v2.1.1(1mo ago)219MITPHPPHP ^8.2|^8.3|^8.4CI passing

Since May 15Pushed 1w ago1 watchersCompare

[ Source](https://github.com/hemilrajput/laravel-typegen)[ Packagist](https://packagist.org/packages/hemilrajput/laravel-typegen)[ RSS](/packages/hemilrajput-laravel-typegen/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)Dependencies (20)Versions (14)Used By (0)

Laravel TypeGen
===============

[](#laravel-typegen)

> **Laravel TypeGen** — one artisan command turns your Eloquent models, Enums, and FormRequests into a single typed `.ts` file. No more hand-syncing PHP and TypeScript.

📖 Documentation
---------------

[](#-documentation)

For complete documentation, guides, and setup instructions, visit [laravel-typegen.github.io](https://hemilrajput.github.io/laravel-typegen/).

Why Laravel TypeGen?
--------------------

[](#why-laravel-typegen)

- **Keeps types in sync**: Automatically reflect changes in your PHP models in your TypeScript interfaces. Generate TypeScript types from Eloquent models, Enums, and FormRequests. Built for the Laravel 13 + Inertia + React/Vue stack.

---

⚡️ The Killer Feature: Synchronized Types
-----------------------------------------

[](#️-the-killer-feature-synchronized-types)

Laravel TypeGen doesn't just generate standalone interfaces. It understands your application's logic.

**PHP Enum + Model Cast:**

```
enum UserRole: string {
    case Admin = 'admin';
}

class User extends Model {
    protected $casts = ['role' => UserRole::class];
}
```

**TypeScript Output:**

```
export type UserRole = 'admin';

export interface User {
    id: number;
    role: UserRole; // Automatically linked!
}
```

---

🚀 Features
----------

[](#-features)

- **Eloquent Models**: Generates interfaces from `$fillable`, `$casts`, and timestamps.
- **Enums**: Generates union types from backed and pure PHP enums.
- **FormRequests**: Generates request DTOs from your `rules()` method.
- **Attribute-Driven**: Opt-in to generation using the `#[TypeScript]` attribute.
- **Zero-Config**: Smart defaults for standard Laravel projects.

📊 Comparison
------------

[](#-comparison)

FeatureTypeGenSpatie TS TransformerEloquent Support✅✅Enum Support✅✅**FormRequest → DTO**✅❌**Relationship Auto-Discovery**✅❌**Linked Enum Casts**✅⚠️ (Manual)Attribute Driven✅✅Inertia Native✅⚠️---

📦 Installation
--------------

[](#-installation)

```
composer require hemilrajput/laravel-typegen
```

🛠 Usage
-------

[](#-usage)

### 1. Tag your classes

[](#1-tag-your-classes)

```
use Hemilrajput\TypeGen\Attributes\TypeScript;

#[TypeScript]
class User extends Model { ... }
```

### 2. Generate

[](#2-generate)

```
php artisan typescript:generate
```

---

🔗 Relationships
---------------

[](#-relationships)

Opt into relationship type generation per-model:

```
#[TypeScript(includeRelations: ['posts', 'profile'])]
class User extends Model { /* ... */ }
```

Related models (`Post`, `Profile`) are **auto-discovered** — no need to mark them separately. Generated output:

```
export interface User {
  id: number;
  posts?: Post[];
  profile?: Profile | null;
}

export interface Post { /* ... */ }
export interface Profile { /* ... */ }
```

Relations are always emitted as **optional** (`?`) because they're only present when eager-loaded. This matches runtime reality.

### Polymorphic relations

[](#polymorphic-relations)

`MorphTo` is auto-supported when you register a morph map:

```
Relation::enforceMorphMap([
    'post' => Post::class,
    'video' => Video::class,
]);
```

Generates:

```
export interface Comment {
  commentable?: (Post | Video) | null;
}
```

Without a morph map, emits `unknown | null` with a comment.

---

🗺 Roadmap
---------

[](#-roadmap)

- Enum support (v0.2)
- FormRequest → DTO (v0.2)
- Eloquent relationships (v0.3)
- Route parameter types (v0.4)
- Watch mode (v0.4)
- Custom Cast class resolver (v0.4)
- VitePress documentation site (v1.0.0)
- Stable release (v1.0.0)

Configuration
-------------

[](#configuration)

See `config/typegen.php` for all available options, including:

- Output path and style (interface vs type).
- Custom cast mapping.
- Prefix/suffix for generated names.
- Including/excluding timestamps and hidden fields.

License
-------

[](#license)

MIT

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance96

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.3% 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 ~3 days

Total

13

Last Release

35d ago

Major Versions

v0.4.0 → v1.0.02026-05-28

v1.3.0 → v2.0.02026-05-29

PHP version history (3 changes)v0.1.0PHP ^8.2

v2.0.0PHP ^8.3

v2.0.1PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86707058?v=4)[Hemil Rajput](/maintainers/hemilrajput)[@hemilrajput](https://github.com/hemilrajput)

---

Top Contributors

[![hemilrajput](https://avatars.githubusercontent.com/u/86707058?v=4)](https://github.com/hemilrajput "hemilrajput (57 commits)")[![Nikhilchudasama](https://avatars.githubusercontent.com/u/20717809?v=4)](https://github.com/Nikhilchudasama "Nikhilchudasama (1 commits)")

---

Tags

laraveleloquenttypescriptinertiatypescodegen

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/hemilrajput-laravel-typegen/health.svg)

```
[![Health](https://phpackages.com/badges/hemilrajput-laravel-typegen/health.svg)](https://phpackages.com/packages/hemilrajput-laravel-typegen)
```

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M246](/packages/laravel-ai)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[illuminate/queue

The Illuminate Queue package.

20432.6M1.7k](/packages/illuminate-queue)[spatie/laravel-health

Monitor the health of a Laravel application

87912.0M177](/packages/spatie-laravel-health)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[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)
