Lens CSV export empty when query ID is not the same as resource model ID #5020
Replies: 5 comments 1 reply
-
|
At the moment there's no reliable way to identify If you can accept to export CSV for "select all" until we can come up with a solution then you can use the following: public function lenses(Request $request): array
{
return [
PaymentsPerEmployee::make()->canSee(function ($request) {
return $request->allResourcesSelected();
}),
];
} |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the answer, I hope you can find a solution soon. I'll stick with the workaround proposal for the moment |
Beta Was this translation helpful? Give feedback.
-
|
I dont understand why this isnt an easy fix. I have tried something that should work in theory, but still isnt. I added an ID field by simply adding an additional select in the lens query with an $query->select('employees.id', 'employees.name', DB::raw('count(payments.id) as count'), 'employees.id as id');And of course in the lenses Now, when I select individual resources and attempt to run the export csv action, i see in the request payload the So i manually checked for the $selectedIds = $request->input('resources');
if ($selectedIds && $selectedIds != 'all') {
$selectedIds = explode(',', $selectedIds);
$query->whereIn('id', $selectedIds);
}Still no dice, the export is still an empty file. Now i am at a loss. If I specify a field in the query to be the |
Beta Was this translation helpful? Give feedback.
-
|
Turns out if I add the following to the action definition in my lens it works perfectly with the above code where i use an The issue is that Novas I feel like if an |
Beta Was this translation helpful? Give feedback.
-
|
I understand that the original poster wants to attach the lens to a different resource than the one that will be used in the Also at no point does Nova stop you from doing this. You can build custom queries in your Lenses and attach them to any resource you want, and it will render fine. You can sort, filter, etc, no worries. Its only when it comes to selecting items and running Actions on them that it suddenly blows up. If you are not meant to put Lenses on anything other than the Resource that will be in the Im not suggesting a significant change in Novas Lens behaviour anyway. What would make this much more flexible is - when resolving the query in the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
When you we have a lens that contains a group by and you try to export data as CSV, it doesn't work when you select individual record. It only works when "Select all" is selected.
This issue only happens when primary key obtained from query does not belongs to the same model as resource.
Detailed steps to reproduce the issue on a fresh Nova installation:
First keep in mind and create the next two models:
Employee:
Payment:
Consider a query like this:
fields:
actions:
Beta Was this translation helpful? Give feedback.
All reactions