Laravel allows to create customCasts for property that do not exist in the database table. This allows to create magic properties as ValueObject which combine multiple attributes together. Currently the ide helper does not provide any docblock for these kind of casts. This PR allows casts without existing properties to be defined as properties.
// model
class CustomCast extends Model
{
protected $casts = [
'price' => MoneyCast::class,
];
}
// cast
class MoneyCast implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes): Money
{
return new Money($attributes['amount'], $attributes['currency']);
}
public function set($model, string $key, $value, array $attributes)
{
return [
$value->amount,
$value->currency,
]
}
}
Type of change
[x] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
Checklist
[x] Existing tests have been adapted and/or new tests have been added
[x] Add a CHANGELOG.md entry
[x] Code style has been fixed via composer fix-style
Summary
Laravel allows to create customCasts for property that do not exist in the database table. This allows to create magic properties as ValueObject which combine multiple attributes together. Currently the ide helper does not provide any docblock for these kind of casts. This PR allows casts without existing properties to be defined as properties.
Type of change
Checklist
composer fix-style