PHPackages                             kiwilan/typescriptable-laravel - 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. kiwilan/typescriptable-laravel

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

kiwilan/typescriptable-laravel
==============================

PHP package for Laravel to type Eloquent models, routes, Spatie Settings with autogenerated TypeScript. If you want to use some helpers with Inertia, you can install associated NPM package.

3.1.06(1y ago)3920.9k↓25.7%8[7 issues](https://github.com/kiwilan/typescriptable-laravel/issues)[7 PRs](https://github.com/kiwilan/typescriptable-laravel/pulls)MITPHPPHP ^8.2 || ^8.4CI passing

Since Jan 28Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/kiwilan/typescriptable-laravel)[ Packagist](https://packagist.org/packages/kiwilan/typescriptable-laravel)[ Docs](https://github.com/kiwilan/typescriptable-laravel)[ RSS](/packages/kiwilan-typescriptable-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (71)Used By (0)

Typescriptable for Laravel
==========================

[](#typescriptable-for-laravel)

[![Banner with printer shop picture in background and Typescriptable Laravel title](https://raw.githubusercontent.com/kiwilan/typescriptable-laravel/main/docs/banner.jpg)](https://raw.githubusercontent.com/kiwilan/typescriptable-laravel/main/docs/banner.jpg)

[![php](https://camo.githubusercontent.com/731af46a12737ef77d62979aae24e91e42c2d5dcad6b2ef112eb0cd421851955/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f7374796c653d666c61742d737175617265266c6162656c3d504850266d6573736167653d76382e3126636f6c6f723d373737424234266c6f676f3d706870266c6f676f436f6c6f723d666666666666266c6162656c436f6c6f723d313831383162)](https://www.php.net/)[![version](https://camo.githubusercontent.com/68872c12c3300f6738d37ccef0b0fadf7b71ce52b0dea3858e05d1d4c79bfd31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6977696c616e2f7479706573637269707461626c652d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d373737424234)](https://packagist.org/packages/kiwilan/typescriptable-laravel)[![downloads](https://camo.githubusercontent.com/63543ba6102db7cbfc63a432104914377b4da5294768339b75615c539787e0bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b6977696c616e2f7479706573637269707461626c652d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d373737424234)](https://packagist.org/packages/kiwilan/typescriptable-laravel)[![license](https://camo.githubusercontent.com/1a4ac84a30241a5e776e7ae228181ee83052591549342750ca74b1c406af3104/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6b6977696c616e2f7479706573637269707461626c652d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d373737424234)](https://github.com/kiwilan/typescriptable-laravel/blob/main/README.md)[![codecov](https://camo.githubusercontent.com/40f886c5d1374756e648ff234cfda67de8e2dbfb75dd941a4133481269d549fa/68747470733a2f2f636f6465636f762e696f2f67682f6b6977696c616e2f7479706573637269707461626c652d6c61726176656c2f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d503958494b324b563947)](https://codecov.io/gh/kiwilan/typescriptable-laravel)[![tests](https://camo.githubusercontent.com/a1bd86934d2767d256a9cd1e2deed00440457b377a0352d5b1ab42557f389279/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6977696c616e2f7479706573637269707461626c652d6c61726176656c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d73717561726526636f6c6f72413d313831383142)](https://github.com/kiwilan/typescriptable-laravel/actions/workflows/run-tests.yml)

[![laravel](https://camo.githubusercontent.com/a57de7ab6683095b08c704f0cc79bc1b75f432eac2b4dd71021145ff2cbcefd5/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d4c61726176656c266d6573736167653d76392d3131267374796c653d666c61742d73717561726526636f6c6f72413d31383138314226636f6c6f72423d464632443230)](https://laravel.com)[![npm](https://camo.githubusercontent.com/21a7c44a34c446d0eff7623c478fbc9657bbd2c67265a73c0d57db31856fb190/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f406b6977696c616e2f7479706573637269707461626c652d6c61726176656c2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d434233383337266c6f676f436f6c6f723d666666666666266c6162656c436f6c6f723d313831383162)](https://www.npmjs.com/package/@kiwilan/typescriptable-laravel)

PHP package for Laravel to type [**Eloquent models**](https://laravel.com/docs/master/eloquent), [**routes**](https://laravel.com/docs/master/routing), [**Spatie Settings**](https://github.com/spatie/laravel-settings) with **autogenerated TypeScript**.

If you want to use some helpers with [Inertia](https://inertiajs.com/), you can install [associated NPM package](#about-npm-package-kiwilantypescriptable-laravel).

[![Eldorado Road Both Scene](https://camo.githubusercontent.com/00e4e0a51900934666df050be577d923d7273c84eee2bfac359691cae89b7cf5/68747470733a2f2f692e67697068792e636f6d2f3166664f7748445a65685662364a6c5269642e77656270)](https://camo.githubusercontent.com/00e4e0a51900934666df050be577d923d7273c84eee2bfac359691cae89b7cf5/68747470733a2f2f692e67697068792e636f6d2f3166664f7748445a65685662364a6c5269642e77656270)

> Because you need PHP and Typescript.

Features
--------

[](#features)

- 💽 Supported Laravel drivers: MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, [MongoDB](https://github.com/mongodb/laravel-mongodb)
- 💬 Generate TS types for [Eloquent models](https://laravel.com/docs/master/eloquent)
- 👭 Generate TS types for [Eloquent relations](https://laravel.com/docs/master/eloquent-relationships)
- 🪄 Generate TS types for [`casts`](https://laravel.com/docs/master/eloquent-mutators#attribute-casting) (include native `enum` support)
- 📝 Generate TS types for `appends` and all [`accessors`](https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators)
    - `Illuminate\Database\Eloquent\Casts\Attribute` with PHPDoc
    - [`get*Attribute`](https://laravel.com/docs/8.x/eloquent-mutators#defining-an-accessor) methods
- \#️⃣ Generate TS types for `counts`
- 📖 Can generate pagination TS types for [Laravel pagination](https://laravel.com/docs/master/pagination)
- 💾 Can generate simple PHP classes from Eloquent models
- ⚙️ Generate TS types for [`spatie/laravel-settings`](https://github.com/spatie/laravel-settings)
- 🛣 Generate TS types for [Laravel routes](https://laravel.com/docs/master/routing)
    - Scan route parameters
    - For Inertia, you can install [`@kiwilan/typescriptable-laravel`](https://github.com/kiwilan/typescriptable-laravel/blob/main/plugin/README.md) NPM package to use some helpers
- ✅ Multiple commands to generate types
    - `php artisan typescriptable` for models, settings and routes (safe even if you don't use all)
    - `php artisan typescriptable:eloquent` for Eloquent models
    - `php artisan typescriptable:settings` for `spatie/laravel-settings`
    - `php artisan typescriptable:routes` for Laravel routes

### Roadmap

[](#roadmap)

- Add parser for [calebporzio/sushi](https://github.com/calebporzio/sushi)
- Add parser for [spatie/laravel-permission](https://github.com/spatie/laravel-permission)

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

[](#installation)

This version requires [PHP](https://www.php.net/) `8.2+` and supports [Laravel](https://laravel.com/) 11.

Warning

Laravel 11 dropped [Doctrine DBAL](https://laravel.com/docs/11.x/upgrade#doctrine-dbal-removal). For previous Laravel versions, you can use `1.12.03` version.

VersionL9L10L11[v3+](https://packagist.org/packages/kiwilan/typescriptable-laravel)❌❌✅[v1.12.03](https://packagist.org/packages/kiwilan/typescriptable-laravel#1.12.03)✅✅❌You can install the package via composer:

With **Laravel v11+** and PHP `8.2`

```
composer require kiwilan/typescriptable-laravel
```

With **Laravel v9-10** and PHP `8.1`

```
composer require kiwilan/typescriptable-laravel:1.12.03

```

### About TypeScript

[](#about-typescript)

If you want to use `.d.ts` files, you need to use TypeScript in your Laravel project, you have to create a `tsconfig.json` file and add `.d.ts` paths in `include`:

Note

If you change paths into config or with options, adapt paths.

```
{
    "compilerOptions": {
        "types": ["vite/client"]
    },
    "include": [
        "resources/js/**/*.ts",
        "resources/js/**/*.d.ts",
        "resources/js/**/*.vue", // If you use Vue
        "*.d.ts",
        "vite.config.ts"
    ]
}
```

 Complete `tsconfig.json`Here is a complete `tsconfig.json` file example (you can adapt paths):

```
{
    "compilerOptions": {
        "target": "esnext",
        "jsx": "preserve",
        "module": "ESNext",
        "moduleResolution": "Node",
        "paths": {
            "@/*": ["./resources/js/*"],
            "@": ["./resources/js"],
            "~": ["./"],
            "~/*": ["./*"]
        },
        "types": ["vite/client"],
        "allowJs": true,
        "strict": true,
        "noEmit": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "isolatedModules": true,
        "skipLibCheck": true
    },
    "include": [
        "resources/js/**/*.ts",
        "resources/js/**/*.d.ts",
        "resources/js/**/*.vue",
        "*.d.ts",
        "vite.config.ts"
    ]
}
```

### About NPM package `@kiwilan/typescriptable-laravel`

[](#about-npm-package-kiwilantypescriptable-laravel)

NPM package is fully optional, you can use only PHP package. It's built for [Vite](https://vitejs.dev/) with [`laravel-vite-plugin`](https://github.com/laravel/vite-plugin) and [Inertia](https://inertiajs.com/) (only for [Vue 3](https://vuejs.org/)). It's SSR compatible.

This package add some helpers to use **Laravel routes** fully typed with TypeScript into Vue components and some composables to use with Vue. The best setup to install this package is to use [Jetstream](https://jetstream.laravel.com), a Laravel starter kit and [`tightenco/ziggy`](https://github.com/tighten/ziggy) is required.

Read full documentation here: [`@kiwilan/typescriptable-laravel`](https://github.com/kiwilan/typescriptable-laravel/blob/main/plugin/README.md).

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

[](#configuration)

You can publish the config file

```
php artisan vendor:publish --tag="typescriptable-config"
```

A config example is available here: [config/typescriptable.php](https://github.com/kiwilan/typescriptable-laravel/blob/main/config/typescriptable.php).

Important

You can configure `engine.eloquent` with `artisan` or `parser` to change parser engine. By default, it uses `artisan` command with [`model:show`](https://blog.laravel.com/laravel-new-model-show-command) command. `artisan` is default engine because it's more reliable and faster than `parser` engine. With MongoDB, the engine doesn't matter because MongoDB database can't be parsed like relational databases.

Usage
-----

[](#usage)

```
php artisan typescriptable
```

With options:

- --`M`|`models`: Generate Models types.
- --`R`|`routes`: Generate Routes types.
- --`S`|`settings`: Generate Settings types.

### Eloquent models

[](#eloquent-models)

Generate `resources/js/types-eloquent.d.ts` file with all models types.

```
php artisan typescriptable:eloquent
```

Options can be set into `config/typescriptable.php` file.

### Spatie Settings

[](#spatie-settings)

If you use [`spatie/laravel-settings`](https://github.com/spatie/laravel-settings), you can generate `resources/js/types-settings.d.ts` file with all settings types.

```
php artisan typescriptable:settings
```

Options can be set into `config/typescriptable.php` file.

### Routes

[](#routes)

Generate `resources/js/types-routes.d.ts` file with all routes types and `resources/js/routes.ts` for routes references.

```
php artisan typescriptable:routes
```

Options can be set into `config/typescriptable.php` file.

### Eloquent listing

[](#eloquent-listing)

Show all Eloquent models with `eloquent:list` command.

```
php artisan eloquent:list
```

Models are parsed from `config/typescriptable.php` with `eloquent.directory` variable.

Advanced
--------

[](#advanced)

### MongoDB

[](#mongodb)

`kiwilan/typescriptable-laravel` supports [MongoDB](https://github.com/mongodb/laravel-mongodb) with `mongodb/laravel-mongodb`. Due to the MongoDB structure, Typescript conversion aren't the same as SQL databases, precision is lower. If you want to improve it, you can add [an issue](https://github.com/kiwilan/typescriptable-laravel/issues/new/choose).

Database isn't parsed like with relational databases. The package will parse `key`, `fillable` and `hidden` to get all fields. If some fields are missing, you can [override them manually](https://github.com/kiwilan/typescriptable-laravel#override-models). All relations and accessors are supported.

### Database prefix

[](#database-prefix)

You can use `prefix` variable into `config/database.php` file.

```
'connections' => [
    'YOUR_DATABASE_CONNECTION' => [
        'prefix' => '',
    ],
],
```

### Override models

[](#override-models)

`kiwilan/typescriptable-laravel` will cover many cases, but if you want to override some models, you can just create a type like `resources/js/types/index.ts` and extends `Model` type.

```
export interface BookAdvanced extends App.Models.Book {
    pivot: {
        created_at: string;
        updated_at: string;
    };
}
```

And you can import custom type in your code when you need to use advanced type.

```

import { ref } from "vue";
import { BookAdvanced } from "@/types";

const book = ref();

```

### Print PHP classes

[](#print-php-classes)

If you want to print PHP classes, you can use `--php-path` option with `php artisan typescriptable:eloquent` command.

```
php artisan typescriptable:eloquent --php-path=app/print
```

These classes will be generated from Eloquent models as real PHP classes.

### Examples

[](#examples)

Check [examples](docs/examples.md) documentation.

[![Example output](tests/docs/example.gif)](tests/docs/example.gif)

### Testing

[](#testing)

Create a `.env` file with your database configuration

```
cp .env.example .env
```

And you can run tests

```
composer test
```

Note

You can check [this gist](https://gist.github.com/ewilan-riviere/101cb03ee381b0adc2a22826d84e7577) to have a Docker database configuration.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Spatie](https://github.com/spatie): for [`spatie/package-skeleton-laravel`](https://github.com/spatie/package-skeleton-laravel)
- [Ewilan Riviere](https://github.com/ewilan-riviere): Author package

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[![](https://user-images.githubusercontent.com/48261459/201463225-0a5a084e-df15-4b11-b1d2-40fafd3555cf.svg)](https://github.com/kiwilan)

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance66

Regular maintenance activity

Popularity40

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 93.5% 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 ~12 days

Recently: every ~60 days

Total

63

Last Release

422d ago

Major Versions

0.2.21 → 1.0.02023-02-21

v1.x-dev → 2.0.02024-03-16

v2.x-dev → 3.0.02024-07-22

PHP version history (3 changes)0.0.1PHP ^8.1

2.0.0PHP ^8.2

3.1.06PHP ^8.2 || ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/58eb34eac9af07c3352e83060e472e1c280838ebe0568692561c00a2cfde9e57?d=identicon)[ewilan-riviere](/maintainers/ewilan-riviere)

---

Top Contributors

[![ewilan-riviere](https://avatars.githubusercontent.com/u/48261459?v=4)](https://github.com/ewilan-riviere "ewilan-riviere (604 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (24 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (16 commits)")[![erikwibowo](https://avatars.githubusercontent.com/u/30565150?v=4)](https://github.com/erikwibowo "erikwibowo (2 commits)")

---

Tags

eloquentinertialaravelmodelsphproutessettingststypescriptvuephplaravelroutesmodeleloquenttypescriptinertiavuetskiwilantypescriptable-laravel

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kiwilan-typescriptable-laravel/health.svg)

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

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591444.8k2](/packages/spiritix-lada-cache)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)

PHPackages © 2026

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