Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Action only via relationship not work with dependent field #6575

Closed
et-hoangdv opened this issue Nov 5, 2024 · 3 comments
Closed

Action only via relationship not work with dependent field #6575

et-hoangdv opened this issue Nov 5, 2024 · 3 comments
Labels
needs more info More information is required

Comments

@et-hoangdv
Copy link

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
@crynobone
Copy link
Member

Can you explain the requirement you used for canSee() and some screenshot to explain the issue better?

@crynobone crynobone added the needs more info More information is required label Nov 5, 2024
@et-hoangdv
Copy link
Author

The requirement here is to send email according to the template to the attendees for each event. So the action of sending email according to the template should only appear on the event detail screen, not the attendees screen.
so I set this action to only appear when there is a relationship.

  1. I go to the event detail page which list all attendees join that event.
    Screenshot 2024-11-06 094455

  2. I select some users and then select the action to send email according to the template.
    Screenshot 2024-11-06 094605

  3. I choose email template. Based on the template type I will get data in DB and fill in input Subject and Content. This is also when error happen.
    Screenshot 2024-11-06 094618

When I select template it will call the action API based on the number of dependent fields I have. And importantly it doesn't pass the other parameters viaResource, viaResourceId, viaRelationship so it causes a 404 error at canSee
Screenshot 2024-11-06 094808

@crynobone
Copy link
Member

Yes it doesn't provide those information because it was not designed to be use in such way.

@laravel laravel locked and limited conversation to collaborators Nov 6, 2024
@crynobone crynobone converted this issue into discussion #6577 Nov 6, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

2 participants