Skip to content
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

How to access the Resource/Model in the Query? #167

Open
MCKLtech opened this issue Sep 13, 2023 · 1 comment
Open

How to access the Resource/Model in the Query? #167

MCKLtech opened this issue Sep 13, 2023 · 1 comment

Comments

@MCKLtech
Copy link

I'm using Laravel Jetstream and each Team has a number of Reviews. I want to export those Reviews. If I place the DownloadExcel action on the Team resource:

public function actions(NovaRequest $request)
    {
        return [
            (new DownloadReviews)->onlyOnDetail()
        ];
    }

I need to modify the query (I assume?):

class DownloadReviews extends DownloadExcel implements FromQuery, WithHeadings, WithMapping
{

    public function query()
    {
        return Reviews::query()
            ->where('team_id', request()->resourceId) //This does not work
            ->latest('created_at');
    }
    
}

The question is, how do I access the Team resource/model in the query function?

@patrickbrouwers
Copy link
Member

I think the way actions are built in Nova, you would have to add the action to the Reviews resource instead and than show the team's reviews on the team/show page.
I'm not sure how to get the resourceId the way you are trying, that would be a question to the Nova team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants