Skip to content

Commit

Permalink
Merge pull request #81 from kiwilan/develop
Browse files Browse the repository at this point in the history
v3.1.03
  • Loading branch information
ewilan-riviere authored Jul 25, 2024
2 parents 3341f28 + 66909e3 commit 6fff240
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
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": "3.1.02",
"version": "3.1.03",
"keywords": [
"kiwilan",
"laravel",
Expand Down
26 changes: 19 additions & 7 deletions src/Typed/Eloquent/EloquentTypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ private function parseModel(Model $model, ?string $prefix): Table

$fillables = $model->getFillable();
$hiddens = $model->getHidden();
$appendeds = $model->getAppends();
$casts = $model->getCasts();
$accessors = $this->parseAccessors($model);

foreach ($table->attributes() as $attribute) {
if (in_array($attribute->name(), $fillables)) {
Expand All @@ -88,21 +88,33 @@ private function parseModel(Model $model, ?string $prefix): Table
}
}

foreach ($appendeds as $append) {
$attr = new SchemaModelAttribute(
name: $append,
foreach ($accessors as $accessor) {
$table->addAttribute($accessor);
}

return $table;
}

/**
* @return SchemaModelAttribute[]
*/
private function parseAccessors(Model $model): array
{
$accessors = [];
foreach ($model->getMutatedAttributes() as $attribute) {
$accessors[] = new SchemaModelAttribute(
name: $attribute,
databaseType: null,
increments: false,
nullable: true,
default: null,
unique: false,
appended: true,
cast: 'accessor'
cast: 'accessor',
);
$table->addAttribute($attr);
}

return $table;
return $accessors;
}

private function parseRelations(\ReflectionClass $reflect)
Expand Down

0 comments on commit 6fff240

Please sign in to comment.