forked from BadChoice/handesk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Attachment.php
33 lines (27 loc) · 1.08 KB
/
Attachment.php
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
<?php
namespace App;
use Illuminate\Support\Facades\Storage;
use PhpImap\IncomingMail;
class Attachment extends BaseModel
{
public function attachable() {
return $this->morphTo();
}
public static function storeAttachmentFromRequest($request, $attachable){
$path = str_replace(" ", "_", $attachable->id . "_" . $request->file('attachment')->getClientOriginalName());
Storage::putFileAs("public/attachments/", $request->file('attachment'), $path );
$attachable->attachments()->create(["path" => $path]);
}
/**
* @param IncomingMail $mail
* @param $attachable
*/
public static function storeAttachmentsFromEmail($mail, $attachable ){
foreach( $mail->getAttachments() as $mailAttachment ) {
$path = str_replace(" ", "_", $attachable->id . "_" . $mailAttachment->name);
Storage::put("public/attachments/" . $path, file_get_contents( $mailAttachment->filePath ));
$attachable->attachments()->create(["path" => $path]);
unlink( $mailAttachment->filePath );
}
}
}