-
I have a I need to export the table in this page, but the Excel is automatically filtered by the owner record: Is there any possible way to do that? Or manually set the query I want to use? I tried using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I am not sure why the export would add a where clause? It should simply take the table or model query and use that one 🤔 |
Beta Was this translation helpful? Give feedback.
-
@pxlrbt the filament-excel/src/Exports/ExcelExport.php Line 278 in c4147a3 I suppose that's because it's inside a relationship. Anyway, I solved it by overriding the public function export()
{
if ($this->modifyQueryBeforeExportUsing) {
app()->call($this->modifyQueryBeforeExportUsing->getClosure(), [
'query' => $this->getQuery(),
'livewire' => $this->getLivewire(),
]);
}
return parent::export();
} Then, I'd do: \App\Filament\Pages\Actions\ExcelExport::make()
->modifyQueryBeforeExportUsing(static function (Builder $query): void {
// Remove the owner record filter from the
// query, to prevent wrong exports.
$query->getQuery()->wheres = array_filter(
$query->getQuery()->wheres,
static function (array $where): bool {
return !array_key_exists('column', $where)
|| $where['column'] !== 'users.id';
}
);
}) Not so pretty solution I think, but works. |
Beta Was this translation helpful? Give feedback.
@pxlrbt the
where
is being added here:filament-excel/src/Exports/ExcelExport.php
Line 278 in c4147a3
I suppose that's because it's inside a relationship.
Anyway, I solved it by overriding the
export
method of thepxlrbt\FilamentExcel\Exports\ExcelExport
class and removing thewhere
before making the export (implementing a custom closure):Then, I'd do: