File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Exports ;
4+
5+ use Maatwebsite \Excel \Concerns \FromArray ;
6+ use Maatwebsite \Excel \Concerns \WithHeadings ;
7+
8+ class ResultsSelectedBulkExport implements FromArray, WithHeadings
9+ {
10+ protected $ results ;
11+
12+ public function __construct (array $ results )
13+ {
14+ $ this ->results = $ results ;
15+ }
16+
17+ public function array (): array
18+ {
19+ return $ this ->results ;
20+ }
21+
22+ public function headings (): array
23+ {
24+ return [
25+ 'id ' ,
26+ 'ping ' ,
27+ 'download ' ,
28+ 'upload ' ,
29+ 'server id ' ,
30+ 'server url ' ,
31+ 'server name ' ,
32+ 'result url ' ,
33+ 'scheduled ' ,
34+ 'successful ' ,
35+ 'data ' ,
36+ 'created at ' ,
37+ ];
38+ }
39+ }
Original file line number Diff line number Diff line change 22
33namespace App \Filament \Resources ;
44
5+ use App \Exports \ResultsSelectedBulkExport ;
56use App \Filament \Resources \ResultResource \Pages ;
67use App \Models \Result ;
78use App \Settings \GeneralSettings ;
1617use Filament \Tables \Columns \IconColumn ;
1718use Filament \Tables \Columns \TextColumn ;
1819use Illuminate \Database \Eloquent \Builder ;
20+ use Illuminate \Database \Eloquent \Collection ;
21+ use Maatwebsite \Excel \Facades \Excel ;
1922
2023class ResultResource extends Resource
2124{
@@ -167,6 +170,14 @@ public static function table(Table $table): Table
167170 ]),
168171 ])
169172 ->bulkActions ([
173+ Tables \Actions \BulkAction::make ('export ' )
174+ ->label ('Export selected ' )
175+ ->icon ('heroicon-o-download ' )
176+ ->action (function (Collection $ records ) {
177+ $ export = new ResultsSelectedBulkExport ($ records ->toArray ());
178+
179+ return Excel::download ($ export , 'results_ ' .now ()->timestamp .'.csv ' , \Maatwebsite \Excel \Excel::CSV );
180+ }),
170181 Tables \Actions \DeleteBulkAction::make (),
171182 ])
172183 ->defaultSort ('created_at ' , 'desc ' );
You can’t perform that action at this time.
0 commit comments