Skip to content

Commit a091b9c

Browse files
authored
Allow casts without property (#1267)
* Allow casts without property * Update changelog
1 parent dd12b7c commit a091b9c

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
1212

1313
### Added
1414
- Add support of variadic parameters in `ide-helper:models` [\#1234 / shaffe-fr](https://github.com/barryvdh/laravel-ide-helper/pull/1234)
15+
- Add support of custom casts without properties [\#1267 / sparclex](https://github.com/barryvdh/laravel-ide-helper/pull/1267)
1516

1617
### Changed
1718
- Move default models helper filename to config [\#1241 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/1241)

src/Console/ModelsCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ public function castPropertiesType($model)
392392
// the `$type` until the `:`
393393
$type = strtok($type, ':');
394394
$realType = class_exists($type) ? ('\\' . $type) : 'mixed';
395+
$this->setProperty($name, null, true, true);
395396
break;
396397
}
397398

tests/Console/ModelsCommand/LaravelCustomCasts/Models/CustomCast.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ class CustomCast extends Model
3434
'extended_casted_property_with_static_return_docblock' => ExtendedSelfCastingCasterWithStaticDocblockReturn::class,
3535
'extended_casted_property_with_this_return_docblock' => ExtendedSelfCastingCasterWithThisDocblockReturn::class,
3636
'casted_property_with_static_return_docblock_and_param' => SelfCastingCasterWithStaticDocblockReturn::class . ':param',
37+
'cast_without_property' => CustomCasterWithReturnType::class,
3738
];
3839
}

tests/Console/ModelsCommand/LaravelCustomCasts/__snapshots__/Test__test__1.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
* @property ExtendedSelfCastingCasterWithStaticDocblockReturn $extended_casted_property_with_static_return_docblock
3535
* @property ExtendedSelfCastingCasterWithThisDocblockReturn $extended_casted_property_with_this_return_docblock
3636
* @property SelfCastingCasterWithStaticDocblockReturn $casted_property_with_static_return_docblock_and_param
37+
* @property \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty $cast_without_property
3738
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast newModelQuery()
3839
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast newQuery()
3940
* @method static \Illuminate\Database\Eloquent\Builder|CustomCast query()
@@ -68,5 +69,6 @@ class CustomCast extends Model
6869
'extended_casted_property_with_static_return_docblock' => ExtendedSelfCastingCasterWithStaticDocblockReturn::class,
6970
'extended_casted_property_with_this_return_docblock' => ExtendedSelfCastingCasterWithThisDocblockReturn::class,
7071
'casted_property_with_static_return_docblock_and_param' => SelfCastingCasterWithStaticDocblockReturn::class . ':param',
72+
'cast_without_property' => CustomCasterWithReturnType::class,
7173
];
7274
}

0 commit comments

Comments
 (0)