-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExportExcelNotification.php
More file actions
102 lines (88 loc) · 2.75 KB
/
Copy pathExportExcelNotification.php
File metadata and controls
102 lines (88 loc) · 2.75 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
declare(strict_types=1);
namespace App\Notifications\Admin;
use App\Models\User;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification as FilamentNotification;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\URL;
class ExportExcelNotification extends Notification
{
use Queueable;
private string $filename;
private User $user;
/**
* Create a new notification instance.
*/
public function __construct(User $user, string $fileName)
{
$this->user = $user;
$this->filename = $fileName;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail', 'database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$mail = (new MailMessage)
->subject(__('notification.export_finished.title'))
->line(__('notification.export_finished.body', ['filename' => $this->filename]))
->action(__('notification.export_finished.action'), $this->generateURL());
if (Storage::disk('filament-excel')->exists($this->filename)) {
$mail->attachData(
Storage::disk('filament-excel')->get($this->filename),
$this->filename,
['mime' => Storage::disk('filament-excel')->mimeType($this->filename)]
);
}
return $mail;
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
public function toDatabase(): array
{
return FilamentNotification::make()
->title(__('notification.export_finished.title'))
->body(__('notification.export_finished.notification'))
->success()
->seconds(5)
->icon('heroicon-o-inbox-in')
->actions([
Action::make('export_excel')
->label(__('filament-excel::notifications.download_ready.download'))
->url($this->generateURL(), shouldOpenInNewTab: true)
->button()
->close(),
])
->getDatabaseMessage();
}
private function generateURL(): string
{
return URL::temporarySignedRoute(
'filament-excel-download',
now()->addHours(24),
['path' => $this->filename]
);
}
}