-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMailDownloadController.php
More file actions
34 lines (28 loc) · 977 Bytes
/
MailDownloadController.php
File metadata and controls
34 lines (28 loc) · 977 Bytes
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
<?php
namespace Vormkracht10\FilamentMails\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
class MailDownloadController extends Controller
{
public function __invoke(...$arguments)
{
if (count($arguments) === 4) {
[$tenant, $mail, $attachment, $filename] = $arguments;
} else {
[$mail, $attachment, $filename] = $arguments;
$tenant = null;
}
$attachmentModel = Config::get('mails.models.attachment');
/** @var \Vormkracht10\Mails\Models\MailAttachment $attachment */
$attachment = $attachmentModel::find($attachment);
$file = Storage::disk($attachment->disk)->path($attachment->storagePath);
return response()->download(
file: $file,
name: $filename,
headers: [
'Content-Type' => $attachment->mime,
]
);
}
}