{"id":22547072,"url":"https://github.com/kiwilan/typescriptable-laravel","last_synced_at":"2025-10-13T15:30:28.475Z","repository":{"id":65545285,"uuid":"594390200","full_name":"kiwilan/typescriptable-laravel","owner":"kiwilan","description":"PHP package for Laravel to type Eloquent models, routes, Spatie Settings with autogenerated TypeScript. Optional NPM package for Inertia.","archived":false,"fork":false,"pushed_at":"2024-07-29T14:37:29.000Z","size":1517,"stargazers_count":30,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-12T09:06:07.170Z","etag":null,"topics":["eloquent","inertia","laravel","models","php","routes","settings","ts","typescript","vue"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/kiwilan/typescriptable-laravel","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kiwilan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-28T12:03:05.000Z","updated_at":"2024-11-10T13:30:44.000Z","dependencies_parsed_at":"2023-12-15T10:28:51.668Z","dependency_job_id":"eb78d980-0339-4de7-8e61-964bd67780ef","html_url":"https://github.com/kiwilan/typescriptable-laravel","commit_stats":{"total_commits":147,"total_committers":3,"mean_commits":49.0,"dds":"0.10204081632653061","last_synced_commit":"de50ec541b554062c39dfdf857f43ace2f71c37f"},"previous_names":[],"tags_count":62,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwilan%2Ftypescriptable-laravel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwilan%2Ftypescriptable-laravel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwilan%2Ftypescriptable-laravel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kiwilan%2Ftypescriptable-laravel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kiwilan","download_url":"https://codeload.github.com/kiwilan/typescriptable-laravel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236360759,"owners_count":19136701,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","inertia","laravel","models","php","routes","settings","ts","typescript","vue"],"created_at":"2024-12-07T15:09:59.359Z","updated_at":"2025-10-13T15:30:28.080Z","avatar_url":"https://github.com/kiwilan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typescriptable for Laravel\n\n![Banner with printer shop picture in background and Typescriptable Laravel title](https://raw.githubusercontent.com/kiwilan/typescriptable-laravel/main/docs/banner.jpg)\n\n[![php][php-version-src]][php-version-href]\n[![version][version-src]][version-href]\n[![downloads][downloads-src]][downloads-href]\n[![license][license-src]][license-href]\n[![codecov][codecov-src]][codecov-href]\n[![tests][tests-src]][tests-href]\n\n[![laravel][laravel-src]][laravel-href]\n[![npm][npm-version-src]][npm-version-href]\n\nPHP 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**.\n\nIf you want to use some helpers with [Inertia](https://inertiajs.com/), you can install [associated NPM package](#about-npm-package-kiwilantypescriptable-laravel).\n\n![Eldorado Road Both Scene](https://i.giphy.com/1ffOwHDZehVb6JlRid.webp)\n\n\u003e Because you need PHP and Typescript.\n\n## Features\n\n-   💽 Supported Laravel drivers: MySQL, MariaDB, PostgreSQL, SQLite, SQL Server, [MongoDB](https://github.com/mongodb/laravel-mongodb)\n-   💬 Generate TS types for [Eloquent models](https://laravel.com/docs/master/eloquent)\n-   👭 Generate TS types for [Eloquent relations](https://laravel.com/docs/master/eloquent-relationships)\n-   🪄 Generate TS types for [`casts`](https://laravel.com/docs/master/eloquent-mutators#attribute-casting) (include native `enum` support)\n-   📝 Generate TS types for `appends` and all [`accessors`](https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators)\n    -   `Illuminate\\Database\\Eloquent\\Casts\\Attribute` with PHPDoc\n    -   [`get*Attribute`](https://laravel.com/docs/8.x/eloquent-mutators#defining-an-accessor) methods\n-   #️⃣ Generate TS types for `counts`\n-   📖 Can generate pagination TS types for [Laravel pagination](https://laravel.com/docs/master/pagination)\n-   💾 Can generate simple PHP classes from Eloquent models\n-   ⚙️ Generate TS types for [`spatie/laravel-settings`](https://github.com/spatie/laravel-settings)\n-   🛣 Generate TS types for [Laravel routes](https://laravel.com/docs/master/routing)\n    -   Scan route parameters\n    -   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\n-   ✅ Multiple commands to generate types\n    -   `php artisan typescriptable` for models, settings and routes (safe even if you don't use all)\n    -   `php artisan typescriptable:eloquent` for Eloquent models\n    -   `php artisan typescriptable:settings` for `spatie/laravel-settings`\n    -   `php artisan typescriptable:routes` for Laravel routes\n\n### Roadmap\n\n-   [ ] Add parser for [calebporzio/sushi](https://github.com/calebporzio/sushi)\n-   [ ] Add parser for [spatie/laravel-permission](https://github.com/spatie/laravel-permission)\n\n## Installation\n\nThis version requires [PHP](https://www.php.net/) `8.2+` and supports [Laravel](https://laravel.com/) 11.\n\n\u003e [!WARNING]\n\u003e\n\u003e 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.\n\n| Version                                                                           | L9                 | L10                | L11                |\n| --------------------------------------------------------------------------------- | ------------------ | ------------------ | ------------------ |\n| [v3+](https://packagist.org/packages/kiwilan/typescriptable-laravel)              | :x:                | :x:                | :white_check_mark: |\n| [v1.12.03](https://packagist.org/packages/kiwilan/typescriptable-laravel#1.12.03) | :white_check_mark: | :white_check_mark: | :x:                |\n\nYou can install the package via composer:\n\nWith **Laravel v11+** and PHP `8.2`\n\n```bash\ncomposer require kiwilan/typescriptable-laravel\n```\n\nWith **Laravel v9-10** and PHP `8.1`\n\n```\ncomposer require kiwilan/typescriptable-laravel:1.12.03\n```\n\n### About TypeScript\n\nIf 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`:\n\n\u003e [!NOTE]\n\u003e\n\u003e If you change paths into config or with options, adapt paths.\n\n```jsonc\n{\n    \"compilerOptions\": {\n        \"types\": [\"vite/client\"]\n    },\n    \"include\": [\n        \"resources/js/**/*.ts\",\n        \"resources/js/**/*.d.ts\",\n        \"resources/js/**/*.vue\", // If you use Vue\n        \"*.d.ts\",\n        \"vite.config.ts\"\n    ]\n}\n```\n\n\u003cdetails\u003e\n  \u003csummary\u003eComplete `tsconfig.json`\u003c/summary\u003e\n\nHere is a complete `tsconfig.json` file example (you can adapt paths):\n\n```json\n{\n    \"compilerOptions\": {\n        \"target\": \"esnext\",\n        \"jsx\": \"preserve\",\n        \"module\": \"ESNext\",\n        \"moduleResolution\": \"Node\",\n        \"paths\": {\n            \"@/*\": [\"./resources/js/*\"],\n            \"@\": [\"./resources/js\"],\n            \"~\": [\"./\"],\n            \"~/*\": [\"./*\"]\n        },\n        \"types\": [\"vite/client\"],\n        \"allowJs\": true,\n        \"strict\": true,\n        \"noEmit\": true,\n        \"esModuleInterop\": true,\n        \"forceConsistentCasingInFileNames\": true,\n        \"isolatedModules\": true,\n        \"skipLibCheck\": true\n    },\n    \"include\": [\n        \"resources/js/**/*.ts\",\n        \"resources/js/**/*.d.ts\",\n        \"resources/js/**/*.vue\",\n        \"*.d.ts\",\n        \"vite.config.ts\"\n    ]\n}\n```\n\n\u003c/details\u003e\n\n### About NPM package `@kiwilan/typescriptable-laravel`\n\nNPM 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.\n\nThis 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.\n\nRead full documentation here: [`@kiwilan/typescriptable-laravel`](https://github.com/kiwilan/typescriptable-laravel/blob/main/plugin/README.md).\n\n## Configuration\n\nYou can publish the config file\n\n```bash\nphp artisan vendor:publish --tag=\"typescriptable-config\"\n```\n\nA config example is available here: [config/typescriptable.php](https://github.com/kiwilan/typescriptable-laravel/blob/main/config/typescriptable.php).\n\n\u003e [!IMPORTANT]\n\u003e\n\u003e 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.\n\n## Usage\n\n```bash\nphp artisan typescriptable\n```\n\nWith options:\n\n-   --`M`|`models`: Generate Models types.\n-   --`R`|`routes`: Generate Routes types.\n-   --`S`|`settings`: Generate Settings types.\n\n### Eloquent models\n\nGenerate `resources/js/types-eloquent.d.ts` file with all models types.\n\n```bash\nphp artisan typescriptable:eloquent\n```\n\nOptions can be set into `config/typescriptable.php` file.\n\n### Spatie Settings\n\nIf 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.\n\n```bash\nphp artisan typescriptable:settings\n```\n\nOptions can be set into `config/typescriptable.php` file.\n\n### Routes\n\nGenerate `resources/js/types-routes.d.ts` file with all routes types and `resources/js/routes.ts` for routes references.\n\n```bash\nphp artisan typescriptable:routes\n```\n\nOptions can be set into `config/typescriptable.php` file.\n\n### Eloquent listing\n\nShow all Eloquent models with `eloquent:list` command.\n\n```bash\nphp artisan eloquent:list\n```\n\nModels are parsed from `config/typescriptable.php` with `eloquent.directory` variable.\n\n## Advanced\n\n### MongoDB\n\n`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).\n\nDatabase 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.\n\n### Database prefix\n\nYou can use `prefix` variable into `config/database.php` file.\n\n```php\n'connections' =\u003e [\n    'YOUR_DATABASE_CONNECTION' =\u003e [\n        'prefix' =\u003e '',\n    ],\n],\n```\n\n### Override models\n\n`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.\n\n```ts\nexport interface BookAdvanced extends App.Models.Book {\n    pivot: {\n        created_at: string;\n        updated_at: string;\n    };\n}\n```\n\nAnd you can import custom type in your code when you need to use advanced type.\n\n```vue\n\u003cscript setup lang=\"ts\"\u003e\nimport { ref } from \"vue\";\nimport { BookAdvanced } from \"@/types\";\n\nconst book = ref\u003cBookAdvanced\u003e();\n\u003c/script\u003e\n```\n\n### Print PHP classes\n\nIf you want to print PHP classes, you can use `--php-path` option with `php artisan typescriptable:eloquent` command.\n\n```bash\nphp artisan typescriptable:eloquent --php-path=app/print\n```\n\nThese classes will be generated from Eloquent models as real PHP classes.\n\n### Examples\n\nCheck [examples](docs/examples.md) documentation.\n\n![Example output](tests/docs/example.gif)\n\n### Testing\n\nCreate a `.env` file with your database configuration\n\n```bash\ncp .env.example .env\n```\n\nAnd you can run tests\n\n```bash\ncomposer test\n```\n\n\u003e [!NOTE]\n\u003e\n\u003e You can check [this gist](https://gist.github.com/ewilan-riviere/101cb03ee381b0adc2a22826d84e7577) to have a Docker database configuration.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\n-   [Spatie](https://github.com/spatie): for [`spatie/package-skeleton-laravel`](https://github.com/spatie/package-skeleton-laravel)\n-   [Ewilan Riviere](https://github.com/ewilan-riviere): Author package\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[\u003cimg src=\"https://user-images.githubusercontent.com/48261459/201463225-0a5a084e-df15-4b11-b1d2-40fafd3555cf.svg\" height=\"120rem\" width=\"100%\" /\u003e](https://github.com/kiwilan)\n\n[version-src]: https://img.shields.io/packagist/v/kiwilan/typescriptable-laravel.svg?style=flat-square\u0026colorA=18181B\u0026colorB=777BB4\n[version-href]: https://packagist.org/packages/kiwilan/typescriptable-laravel\n[php-version-src]: https://img.shields.io/static/v1?style=flat-square\u0026label=PHP\u0026message=v8.1\u0026color=777BB4\u0026logo=php\u0026logoColor=ffffff\u0026labelColor=18181b\n[php-version-href]: https://www.php.net/\n[npm-version-src]: https://img.shields.io/npm/v/@kiwilan/typescriptable-laravel.svg?style=flat-square\u0026color=CB3837\u0026logoColor=ffffff\u0026labelColor=18181b\n[npm-version-href]: https://www.npmjs.com/package/@kiwilan/typescriptable-laravel\n[downloads-src]: https://img.shields.io/packagist/dt/kiwilan/typescriptable-laravel.svg?style=flat-square\u0026colorA=18181B\u0026colorB=777BB4\n[downloads-href]: https://packagist.org/packages/kiwilan/typescriptable-laravel\n[license-src]: https://img.shields.io/github/license/kiwilan/typescriptable-laravel.svg?style=flat-square\u0026colorA=18181B\u0026colorB=777BB4\n[license-href]: https://github.com/kiwilan/typescriptable-laravel/blob/main/README.md\n[tests-src]: https://img.shields.io/github/actions/workflow/status/kiwilan/typescriptable-laravel/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square\u0026colorA=18181B\n[tests-href]: https://github.com/kiwilan/typescriptable-laravel/actions/workflows/run-tests.yml\n[codecov-src]: https://codecov.io/gh/kiwilan/typescriptable-laravel/branch/main/graph/badge.svg?token=P9XIK2KV9G\n[codecov-href]: https://codecov.io/gh/kiwilan/typescriptable-laravel\n[laravel-src]: https://img.shields.io/static/v1?label=Laravel\u0026message=v9-11\u0026style=flat-square\u0026colorA=18181B\u0026colorB=FF2D20\n[laravel-href]: https://laravel.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiwilan%2Ftypescriptable-laravel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkiwilan%2Ftypescriptable-laravel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkiwilan%2Ftypescriptable-laravel/lists"}