Skip to content

Filling fields which depend on another field depends on the order of field definition in the schema #65

@X-Coder264

Description

@X-Coder264

When the filling logic of a field depends on another field we can use the fillUsing method of an attribute to customize the filling logic. In doing so the order of the field definitions matters as the hydrator goes in order and hydrates each field.

Laravel Nova gets the entire request when it hydrates a field:

Text::make('Name', 'name')
    ->fillUsing(function ($request, $model, $attribute, $requestAttribute) {
        $model->{$attribute} = Str::title($request->input($attribute));
    }),

We could pass the entire validated request data in the fillUsing Closure too, so that we don't have to depend on the field definition order.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions