Skip to content

Pivot actions with (dependsOn) fields do not work #6837

@royduin

Description

@royduin

With Nova 5.6.0 we're using pivot actions: https://nova.laravel.com/docs/v5/actions/registering-actions#pivot-actions with (dependsOn) fields, but this results in 404 errors on the endpoints being called when the fields change (select something from a dropdown):

/nova-api/products/action?action=reorder&resources%5B%5D=22924&resources%5B%5D=23697&editing=true&editMode=create&field=amount&component=number.text-field.amount

As the action can't be found on the resource with availableActions() in the ActionController.php. This should also check the pivot actions.

Reproduce

ShopResource.php

MorphToMany::make(__('Products'), 'products', ProductResource::class)
    ->fields(fn () => [
        Number::make(__('Sort order'), 'sort_order'),
    ])
    ->actions(fn () => [
        new SortableAction,
    ]),

SortableAction.php

public function fields(NovaRequest $request): array
{
    return [
        Select::make(__('Sorting'), 'sorting')->options([
            'moveToStart' => 'moveToStart',
            'moveToEnd' => 'moveToEnd',
            'moveUpBy' => 'moveUpBy',
            'moveDownBy' => 'moveDownBy',
        ])->required(),

        Number::make(__('Amount'), 'amount')
            ->hide()
            ->dependsOn(['sorting'], function (Number $field, NovaRequest $request, FormData $formData) {
                if (in_array($formData->get('sorting'), ['moveUpBy', 'moveDownBy'])) {
                    $field->show()->rules('required');
                }
            })
    ];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions