36 lines
771 B
PHP
36 lines
771 B
PHP
<?php
|
|
|
|
namespace App\Services\Email;
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
|
|
class EmailAttachmentService
|
|
{
|
|
public function normalize($files): array
|
|
{
|
|
if ($files instanceof UploadedFile) {
|
|
$files = [$files];
|
|
}
|
|
if (!is_array($files)) {
|
|
return [];
|
|
}
|
|
|
|
$out = [];
|
|
foreach ($files as $file) {
|
|
if (!$file instanceof UploadedFile || !$file->isValid()) {
|
|
continue;
|
|
}
|
|
$path = $file->getRealPath();
|
|
if (!$path || !is_file($path)) {
|
|
continue;
|
|
}
|
|
$out[] = [
|
|
'path' => $path,
|
|
'name' => $file->getClientOriginalName(),
|
|
];
|
|
}
|
|
|
|
return $out;
|
|
}
|
|
}
|