From a5099b807f4dc182cc328590320488646439a1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Gaulin?= Date: Sat, 4 Apr 2020 14:30:55 +0400 Subject: [PATCH] Add inline url --- src/Attachment.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Attachment.php b/src/Attachment.php index efa0e76..6e1fde4 100644 --- a/src/Attachment.php +++ b/src/Attachment.php @@ -282,6 +282,23 @@ public function getUrlAttribute() } } + public function getUrlInlineAttribute() + { + if ($this->isLocalStorage()) { + $extension = $this->extension; + + return route('attachments.download', [ + 'id' => $this->uuid, + 'name' => $extension ? + Str::slug(substr($this->filename, 0, -1 * strlen($this->extension) - 1)) . '.' . $this->extension : + Str::slug($this->filename), + 'disposition' => 'inline', + ]); + } else { + return Storage::disk($this->disk)->url($this->filepath); + } + } + public function toArray() { @@ -572,4 +589,4 @@ public function getConnectionName() { return config('attachments.database.connection') ?? $this->connection; } -} \ No newline at end of file +}