diff --git a/app/Exports/ResultsSelectedBulkExport.php b/app/Exports/ResultsSelectedBulkExport.php new file mode 100644 index 000000000..68b655322 --- /dev/null +++ b/app/Exports/ResultsSelectedBulkExport.php @@ -0,0 +1,39 @@ +results = $results; + } + + public function array(): array + { + return $this->results; + } + + public function headings(): array + { + return [ + 'id', + 'ping', + 'download', + 'upload', + 'server id', + 'server url', + 'server name', + 'result url', + 'scheduled', + 'successful', + 'data', + 'created at', + ]; + } +} diff --git a/app/Filament/Resources/ResultResource.php b/app/Filament/Resources/ResultResource.php index 5108a08d8..a74758e4c 100644 --- a/app/Filament/Resources/ResultResource.php +++ b/app/Filament/Resources/ResultResource.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources; +use App\Exports\ResultsSelectedBulkExport; use App\Filament\Resources\ResultResource\Pages; use App\Models\Result; use App\Settings\GeneralSettings; @@ -16,6 +17,8 @@ use Filament\Tables\Columns\IconColumn; use Filament\Tables\Columns\TextColumn; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; +use Maatwebsite\Excel\Facades\Excel; class ResultResource extends Resource { @@ -167,6 +170,14 @@ public static function table(Table $table): Table ]), ]) ->bulkActions([ + Tables\Actions\BulkAction::make('export') + ->label('Export selected') + ->icon('heroicon-o-download') + ->action(function (Collection $records) { + $export = new ResultsSelectedBulkExport($records->toArray()); + + return Excel::download($export, 'results_'.now()->timestamp.'.csv', \Maatwebsite\Excel\Excel::CSV); + }), Tables\Actions\DeleteBulkAction::make(), ]) ->defaultSort('created_at', 'desc');