-
|
Currently, the return value of the closure provided to the withQuery() method is ignored. There is no apparent way to customize (replace) the query used to export the data beyond what the Builder fluent interface permits. A simple change to the dispatchRequestUsing() method of the ExportAsCsv action would suffice to permit replacing the query. Whereas currently the return value of the Closure appears dropped, it could be instead considered if not nullish, e.g.: $query = $query->when($this->withQueryCallback instanceof Closure, function ($query) use ($fields) {
return call_user_func($this->withQueryCallback, $query, $fields);
}) ?? query;Permitting for the query to be replaced, would enable the ExportAsCsv action to be used in more contexts. For example, it could be used as a sole action on a resource to export related resource data, or some more complex reports. // e.g. roughly, an action on a blog Post Nova resource
ExportAsCsv::make('Export All Comments')
->sole()
->withQuery(fn () => Comment::where('post_id', $this->resource->id); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This is a bit misguided. $this->resource would not be available in the closure. The only place where the resource ids available once in the closure are in the $query. It's probably best to leftJoin() the existing query in the attempted example above. ExportAsCsv::make('Export All Comments')
->sole()
->withQuery(fn ($query) => $query->leftJoin('comments', 'comments.post_id', '=', 'post.id')); // or some suchPlease ignore / delete. |
Beta Was this translation helpful? Give feedback.
This is a bit misguided. $this->resource would not be available in the closure. The only place where the resource ids available once in the closure are in the $query. It's probably best to leftJoin() the existing query in the attempted example above.
Please ignore / delete.