diff --git a/README.md b/README.md index 2b6ead8..54565c6 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,20 @@ [![php][php-version-src]][php-version-href] [![laravel][laravel-src]][laravel-href] [![version][version-src]][version-href] -[![npm][npm-version-src]][npm-version-href] [![downloads][downloads-src]][downloads-href] [![license][license-src]][license-href] [![tests][tests-src]][tests-href] [![codecov][codecov-src]][codecov-href] +[![npm][npm-version-src]][npm-version-href] + PHP package for Laravel **to type Eloquent models**, **routes**, [**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](https://www.npmjs.com/package/@kiwilan/typescriptable-laravel). -> **Note** +> [!NOTE] > -> - [`kiwilan/typescriptable-laravel`](https://packagist.org/packages/kiwilan/typescriptable-laravel): PHP package for [Laravel](https://laravel.com/). +> - [`kiwilan/typescriptable-laravel`](https://packagist.org/packages/kiwilan/typescriptable-laravel): current PHP package for [Laravel](https://laravel.com/). > - [`@kiwilan/typescriptable-laravel`](https://www.npmjs.com/package/@kiwilan/typescriptable-laravel): optional NPM package to use with [Vite](https://vitejs.dev/) and [Inertia](https://inertiajs.com/) to have some helpers, if you want to know more about, [check documentation](https://github.com/kiwilan/typescriptable-laravel/blob/main/lib/README.md). > - [`ziggy`](https://github.com/tighten/ziggy) is **NOT REQUIRED** @@ -39,7 +40,7 @@ If you want to use some helpers with [Inertia](https://inertiajs.com/), you can - Scan route parameters - For Inertia, you can install [`@kiwilan/typescriptable-laravel`](https://www.npmjs.com/package/@kiwilan/typescriptable-laravel) NPM package to use some helpers - ✅ Multiple commands to generate types - - `php artisan typescriptable` for all + - `php artisan typescriptable` for models, settings and routes (safe even if you don't use all) - `php artisan typescriptable:models` for Eloquent models - `php artisan typescriptable:settings` for `spatie/laravel-settings` - `php artisan typescriptable:routes` for Laravel routes @@ -67,7 +68,7 @@ composer require kiwilan/typescriptable-laravel 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 `compilerOptions.types`: -> **Note** +> [!NOTE] > > If you change paths into config or with options, adapt paths. @@ -177,7 +178,7 @@ composer test ### Docker database -> **Note** +> [!NOTE] > > To install this on M1 Mac, you need to enable `Use Rosetta for x86/amd64 emulation on Apple Silicon` in Docker preferences. @@ -217,7 +218,7 @@ docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=12345OHdf%e" \ mcr.microsoft.com/mssql/server:2022-latest ``` -> **Warning** +> [!WARNING] > > If you have an error like this: "An invalid attribute was designated on the PDO object", you have to update `msphpsql` driver. Check for more information. diff --git a/composer.json b/composer.json index add4d78..da47e02 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "kiwilan/typescriptable-laravel", "description": "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.", - "version": "1.11.31", + "version": "1.11.32", "keywords": [ "kiwilan", "laravel", diff --git a/src/Typed/Eloquent/Utils/EloquentRelation.php b/src/Typed/Eloquent/Utils/EloquentRelation.php index 06f5204..393ceaf 100644 --- a/src/Typed/Eloquent/Utils/EloquentRelation.php +++ b/src/Typed/Eloquent/Utils/EloquentRelation.php @@ -187,7 +187,11 @@ private function parseMorphModel(ReflectionMethod $method) $this->hasPivot = true; $this->phpType = $related; - $this->typescriptType = "App.Models.{$related}"; + + $tsModel = explode('\\', $related); + $this->pivotModel = $tsModel[count($tsModel) - 1]; + $this->typescriptType = 'App.Models.'.$tsModel[count($tsModel) - 1]; + if ($this->isArray) { $this->typescriptType .= '[]'; }