Replies: 1 comment
-
|
If I understand correctly what you're trying to achieve, then this can already be done via Eloquent attributes (accessors) rather than their native PHP namesake: /**
* @return \Illuminate\Database\Eloquent\Casts\Attribute<callable(): string, callable(string): array{first_name: string}>
*/
public function givenName(): Attribute
{
return Attribute::make(
get: fn (): string => $this->first_name,
set: fn (string $value): array => ['first_name' => $value],
);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using Laravel ORM, a common issue is that we often need to rely on PHPDoc annotations to describe the properties of a model. Is it possible for Laravel to introduce something like an attribute-based mapping in the ORM, such as
#[Column('id')], to decouple database column names from object property names?This way, we could directly map database fields to differently named properties on the model, which would make the overall usage feel more convenient and expressive.
We could introduce attribute-based mappings:
Beta Was this translation helpful? Give feedback.
All reactions