Feature Description
Laravel Data allows mapping property names using the following attributes:
#[MapInputName(...)] - Instantiating from an array
#[MapOutputName()...] - Transforming to an array
#[MapName(...)] - Both
You can pass a built in mapper:
SnakeCaseMapper::class
CamelCaseMapper::class
SnakeCaseMapper::class
StudlyCaseMapper::class
UpperCaseMapper::class
LowerCaseMapper::class
... or provide a string e.g. #[MapName('my_property')].
The attributes can be used at a class- or property-level.
It would be nice to see these reflected in autocompletions. Currently, autocompletions are only provided for the properties as defined on the class, for example:
#[MapName(SnakeCaseMapper::class)]
class UserDto extends Data
{
public function __construct(
#[MapName('email_address')] public string $username,
public string $phoneNumber,
) {}
}
UserDto::from([
'email_address' => 'test@example.com', // No autocomplete
'phone_number' => 01234567890, // Autocompletes to "phoneNumber" when typing "phone"
]);
Feature Description
Laravel Data allows mapping property names using the following attributes:
#[MapInputName(...)]- Instantiating from an array#[MapOutputName()...]- Transforming to an array#[MapName(...)]- BothYou can pass a built in mapper:
SnakeCaseMapper::classCamelCaseMapper::classSnakeCaseMapper::classStudlyCaseMapper::classUpperCaseMapper::classLowerCaseMapper::class... or provide a string e.g.
#[MapName('my_property')].The attributes can be used at a class- or property-level.
It would be nice to see these reflected in autocompletions. Currently, autocompletions are only provided for the properties as defined on the class, for example: