From 3055bfa196fc866a3fd65dcae78b927663a33109 Mon Sep 17 00:00:00 2001 From: fsociety Date: Fri, 25 Oct 2024 20:06:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20feat(notification):=20add=20priv?= =?UTF-8?q?ate=20disk=20for=20PDF=20uploads=20and=20update=20download=20ro?= =?UTF-8?q?ute=20with=20signed=20URL.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Notification.php | 3 +- config/filesystems.php | 8 ++++- .../pages/association/news/index.blade.php | 29 +++++++++++-------- routes/web.php | 8 +++++ 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/Models/Notification.php b/app/Models/Notification.php index 675658a..3364b11 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -26,7 +26,8 @@ class Notification extends Model implements HasMedia $this ->addMediaCollection('pdf') ->acceptsMimeTypes(['application/pdf']) - ->singleFile(); + ->singleFile() + ->useDisk('private'); } public function einundzwanzigPleb(): BelongsTo diff --git a/config/filesystems.php b/config/filesystems.php index c5f244d..587fbcf 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -36,10 +36,16 @@ return [ 'throw' => false, ], + 'private' => [ + 'driver' => 'local', + 'root' => storage_path('app/private'), + 'throw' => false, + ], + 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'url' => env('APP_URL') . '/storage', 'visibility' => 'public', 'throw' => false, ], diff --git a/resources/views/pages/association/news/index.blade.php b/resources/views/pages/association/news/index.blade.php index 737090b..af9a433 100644 --- a/resources/views/pages/association/news/index.blade.php +++ b/resources/views/pages/association/news/index.blade.php @@ -60,14 +60,15 @@ $save = function () { $notification = \App\Models\Notification::query() ->orderBy('created_at', 'desc') ->create([ - 'einundzwanzig_pleb_id' => $this->currentPleb->id, - 'category' => $this->form->category, - 'name' => $this->form->name, - 'description' => $this->form->description, - ]); + 'einundzwanzig_pleb_id' => $this->currentPleb->id, + 'category' => $this->form->category, + 'name' => $this->form->name, + 'description' => $this->form->description, + ]); $notification ->addMedia($this->file->getRealPath()) + ->usingName($this->file->getClientOriginalName()) ->toMediaCollection('pdf'); $this->form->reset(); @@ -78,7 +79,7 @@ $save = function () { ->get(); }; -$delete = function($id) { +$delete = function ($id) { $notification = new WireNotification($this); $notification->confirm([ 'title' => 'Post löschen', @@ -91,7 +92,7 @@ $delete = function($id) { ]); }; -$deleteNow = function($id) { +$deleteNow = function ($id) { $notification = \App\Models\Notification::query()->find($id); $notification->delete(); $this->news = \App\Models\Notification::query() @@ -142,8 +143,10 @@ $deleteNow = function($id) {