Skip to content

[Feature Request]: Support MapName attributes in spatie/laravel-data autocompletions #1311

@oli-laban

Description

@oli-laban

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"
]);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions