Skip to content

Commit

Permalink
Merge pull request #43 from kiwilan/develop
Browse files Browse the repository at this point in the history
v1.11.32
  • Loading branch information
ewilan-riviere authored Jan 6, 2024
2 parents c48c671 + 4086c74 commit 0add1b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 <https://github.com/laravel/framework/issues/47937> for more information.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 5 additions & 1 deletion src/Typed/Eloquent/Utils/EloquentRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '[]';
}
Expand Down

0 comments on commit 0add1b9

Please sign in to comment.