Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
royduin opened this issue May 1, 2025 · 5 comments
Open

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

royduin opened this issue May 1, 2025 · 5 comments
Labels
needs more info More information is required

Comments

@royduin
Copy link

royduin commented May 1, 2025

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');
                }
            })
    ];
}
@crynobone
Copy link
Member

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone crynobone added the needs more info More information is required label May 1, 2025
@royduin
Copy link
Author

royduin commented May 1, 2025

Ah sorry, didn't know that's required, I'll create one shortly.

Copy link

stale bot commented May 6, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 6, 2025
@royduin
Copy link
Author

royduin commented May 27, 2025

I'll add an example tomorrow

@stale stale bot removed the stale label May 27, 2025
@royduin
Copy link
Author

royduin commented May 27, 2025

Correction, today 🚀 https://github.com/royduin/nova-bug and the example code: royduin/nova-bug@c56743b

  • Login to Nova
  • Create a product /nova/resources/product-resources/new
  • Create a shop /nova/resources/shop-resources/new
  • Open the shop and attach a product /nova/resources/shop-resources/1/attach/product-resources?polymorphic=1&viaRelationship=products
  • Select the product /nova/resources/shop-resources/1
  • Select the sortable action from the dropdown
  • Select a sorting option and check the network tab from the browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

2 participants