LeanAdmin / feature-discussions

The place for discussing new features
6 stars 0 forks source link

Define HasMany fields using string field names #20

Closed stancl closed 3 years ago

stancl commented 3 years ago

Originally suggested by @aiojoshua https://github.com/orgs/LeanAdmin/teams/customers/discussions/7

I would like to offer a suggestion for enhancing the ease of setting up HasMany relation fields.

Being able to pass in an array of field name strings instead of building field objects (referencing fields that were setup on the Resource's fields() function).

Take the following Resource fields function as an example:

public static function fields(): array
    {
        return [
            ID::make('id'),

            Text::make('name')
                ->label('Full name'),

            Text::make('rfc_reason')
                ->label('Reason'),
        ];
    }

When setting up a HasMany field of this resource, we could quickly set which fields to show with a flat string array. This would then fetch the fields by name from the Resource.

->fields([ 'name', 'rfc_reason' ])

I think this would help with saving time and avoiding repetitive field constructors.