-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExportAction.php
More file actions
78 lines (62 loc) · 2.87 KB
/
ExportAction.php
File metadata and controls
78 lines (62 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace App\Filament\Resources\DonationResource\Actions;
use App\Filament\Exports\ExcelExportWithNotificationInDB;
use App\Filament\Resources\DonationResource;
use App\Models\Donation;
use Filament\Notifications\Notification;
use Illuminate\Support\Str;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction as BaseAction;
use pxlrbt\FilamentExcel\Columns\Column;
class ExportAction extends BaseAction
{
protected string | null $status = null;
protected function setUp(): void
{
parent::setUp();
$this->color('secondary');
try {
$this->exports([
ExcelExportWithNotificationInDB::make()
->withFilename(fn () => sprintf(
'%s-%s',
now()->format('Y_m_d-H_i_s'),
Str::slug(DonationResource::getPluralModelLabel()),
))
->fromTable()
->withColumns([
Column::make('id')
->heading('ID'),
Column::make('organization.name')
->formatStateUsing(fn ($state) => Str::upper($state))
->heading(__('organization.label.singular')),
Column::make('project.name')
->formatStateUsing(fn ($state) => Str::upper($state))
->heading(__('project.label.singular')),
Column::make('full_name')
->formatStateUsing(fn ($state) => Str::upper($state))
->heading(__('donation.labels.full_name')),
Column::make('amount')
->heading(__('donation.labels.amount')),
Column::make('created_at')
->formatStateUsing(fn (Donation $record) => $record->created_at->toFormattedDateTime())
->heading(__('donation.labels.created_at')),
Column::make('updated_at')
->formatStateUsing(fn (Donation $record) => $record->updated_at?->toFormattedDateTime())
->heading(__('donation.labels.status_updated_at')),
Column::make('status')
->formatStateUsing(fn (Donation $record) => $record->status->label())
->heading(__('donation.labels.status')),
])
->queue(),
]);
} catch (\Throwable $exception) {
logger()->error($exception->getMessage());
Notification::make('export')
->title(__('notification.export.error.title'))
->body(__('notification.export.error.body'))
->danger()
->send();
}
}
}