SpartnerNL / Laravel-Nova-Excel

🚀 Supercharged Excel exports for Laravel Nova Resources
https://docs.laravel-excel.com/nova/1.0/
MIT License
378 stars 73 forks source link

Allow for "Select All on Current Page" to work with Lenses that use aggregates #126

Closed matthewjumpsoffbuildings closed 3 years ago

matthewjumpsoffbuildings commented 3 years ago

As per issue #90 - when using an export query that is not forAllMatchingResources, the default behaviour was to use the Laravel withKey which selects the primary key (usually id) of the Resource in question, disregarded the key of the Lens for that resource (which may be an aggregate lens using COUNT() and GROUP BY SQL)

The solution as best as I can see, is to allow overriding this behaviour using a withExportQueryKey() option that lets the user specify a different key for a Lens Action. If there is a cleaner or more 'Laravel' way to do it, that would be great, but this does fix the issue and let me use paginated downloadable Excel Actions from aggregate Lenses.

patrickbrouwers commented 3 years ago

@matthewjumpsoffbuildings there's not way to get the lens key via the resource or lens?

matthewjumpsoffbuildings commented 3 years ago

@patrickbrouwers as per my comment in #90 I think the only possible solution is to check the query for a group clause and if its a single column, use that?

Also can you clarify why my PR is failing the styleCI check? edit nvm, double spaced phpdoc params

matthewjumpsoffbuildings commented 3 years ago

@patrickbrouwers I will make another PR with the detection of group clause

patrickbrouwers commented 3 years ago

Thanks, no need to worry about styleci details, it will be auto fixed on merge anyway.