Skip to content

Dynamic action name breaks the submission #5926

@whisust

Description

@whisust
  • Laravel Version: 9.52.16
  • Nova Version: 4.27.13
  • PHP Version: 8.1

Description:

When using a dynamic value in the name() method of an action, you can not submit the action anymore and get a 404 from Nova, as the action's name is used like an identifier in the submission url, and modified between the action generation and its execution.

Detailed steps to reproduce the issue on a fresh Nova installation:

Using the following action on a Resource:

<?php

namespace App\Nova\Actions;

use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;

class ActionWithDynamicName extends Action
{
    public function handle(ActionFields $fields, Collection $models)
    {
        $msg = 'Clicked!';
        return Action::message($msg);
    }

    public function fields(NovaRequest $request)
    {
        return [];
    }

    public function name(): string
    {
        $name = 'Run Something' . rand(1, 100);
        return  $name;
    }
}

and plugging it in your resource

    public function actions(NovaRequest $request)
    {
        return [
            (new ActionWithDynamicName())->showInline(),
        ];
    }

You have a displayed name when selecting the action:

Capture d’écran 2023-10-03 à 16 38 08

And when validating in the modal, the generated URL does not match the Action name anymore

Capture d’écran 2023-10-03 à 16 38 23

Expected

I expect to be able to customize my action name freely, as it's a display label, and not a class / behavior identifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions