Skip to content

Action only via relationship not work with dependent field #6575

@258034-DuongVietHoang

Description

@258034-DuongVietHoang

I have Event and Attendee resources which have many to many relationship.

I have an action of Attendee that need to only show up on Event resource detail page.

class Attendee extends Resource
{
public function actions(NovaRequest $request): array
    {
        return [
            (new SendMailByTemplate)->showInline()->canSee(function (NovaRequest $request) {
                return $request->viaRelationship();
            }),
        ];
    }
}
class SendMailByTemplate extends Action
{
    public function fields(NovaRequest $request)
    {
        return [
            Select::make(__('Template'), 'template')
                ->options(...),

            Text::make(__('Subject'), 'subject')
                ->dependsOn(
                    ['template'],
                    function (Text $field, NovaRequest $request, FormData $formData) use ($mailTemplates) {
                        if ($formData->template){
                            // set value
                        }
                    }
                ),
        ];
    }
}

This is work fine until I change the select option of the template field which it will call an "action API" which not pass params like viaResource, viaResourceId, viaRelationship which make the canSee return false everytime.

I have temporarily fixed it by change the canSee condition but I don't know if that a right way.

(new SendMailByTemplate)->showInline()->canSee(function (NovaRequest $request) {
                return $request->viaRelationship() || !empty($request->resources);
            }),
  • Laravel Version: 11
  • Nova Version: 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions