From db041f6e55c80a8e54b7bbc9af1b89741591b6b2 Mon Sep 17 00:00:00 2001 From: sawirricardo Date: Tue, 14 Jun 2022 15:53:48 +0700 Subject: [PATCH 1/4] include reason optionally --- resources/views/components/threads/thread-menu.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/views/components/threads/thread-menu.blade.php b/resources/views/components/threads/thread-menu.blade.php index f73ed4320..bbcf798ec 100644 --- a/resources/views/components/threads/thread-menu.blade.php +++ b/resources/views/components/threads/thread-menu.blade.php @@ -50,5 +50,6 @@ class="absolute top-12 right-1 flex flex-col bg-white rounded shadow w-48" title="Delete Thread" >

Are you sure you want to delete this thread and its replies? This cannot be undone.

+ @endcanany From 89de0c9320aa72a2a1c90483487160e87eba7dad Mon Sep 17 00:00:00 2001 From: sawirricardo Date: Tue, 14 Jun 2022 15:54:17 +0700 Subject: [PATCH 2/4] Create ThreadDeletedNotification.php --- .../ThreadDeletedNotification.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 app/Notifications/ThreadDeletedNotification.php diff --git a/app/Notifications/ThreadDeletedNotification.php b/app/Notifications/ThreadDeletedNotification.php new file mode 100644 index 000000000..5511e2403 --- /dev/null +++ b/app/Notifications/ThreadDeletedNotification.php @@ -0,0 +1,34 @@ +line("The thread '{$this->thread->subject()}' #{$this->thread->getKey()} was deleted by the moderator") + ->line('with the following reasons:') + ->line($this->reason) + ->line('Thank you'); + } +} From d50ece8ba30d0ea8089e630c9176b7115e4b806a Mon Sep 17 00:00:00 2001 From: sawirricardo Date: Tue, 14 Jun 2022 15:54:42 +0700 Subject: [PATCH 3/4] send email if reason is filled --- app/Http/Controllers/Forum/ThreadsController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Http/Controllers/Forum/ThreadsController.php b/app/Http/Controllers/Forum/ThreadsController.php index 1da75b1c9..bf9370cef 100644 --- a/app/Http/Controllers/Forum/ThreadsController.php +++ b/app/Http/Controllers/Forum/ThreadsController.php @@ -18,6 +18,7 @@ use App\Models\Tag; use App\Models\Thread; use App\Models\User; +use App\Notifications\ThreadDeletedNotification; use App\Policies\ThreadPolicy; use Illuminate\Auth\Middleware\Authenticate; use Illuminate\Auth\Middleware\EnsureEmailIsVerified; @@ -122,6 +123,12 @@ public function delete(Thread $thread) { $this->authorize(ThreadPolicy::DELETE, $thread); + request()->whenFilled('reason', function () use ($thread) { + $thread->author()?->notify( + new ThreadDeletedNotification($thread, request('reason')) + ); + }); + $this->dispatchSync(new DeleteThread($thread)); $this->success('forum.threads.deleted'); From b0454757448872a97ee859a2c6cfb450baf62da7 Mon Sep 17 00:00:00 2001 From: sawirricardo Date: Tue, 14 Jun 2022 15:58:45 +0700 Subject: [PATCH 4/4] fix styleci check --- app/Http/Controllers/Forum/ThreadsController.php | 2 +- app/Notifications/ThreadDeletedNotification.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Controllers/Forum/ThreadsController.php b/app/Http/Controllers/Forum/ThreadsController.php index bf9370cef..37524b0c7 100644 --- a/app/Http/Controllers/Forum/ThreadsController.php +++ b/app/Http/Controllers/Forum/ThreadsController.php @@ -125,7 +125,7 @@ public function delete(Thread $thread) request()->whenFilled('reason', function () use ($thread) { $thread->author()?->notify( - new ThreadDeletedNotification($thread, request('reason')) + new ThreadDeletedNotification($thread, request('reason')), ); }); diff --git a/app/Notifications/ThreadDeletedNotification.php b/app/Notifications/ThreadDeletedNotification.php index 5511e2403..bfd12fc34 100644 --- a/app/Notifications/ThreadDeletedNotification.php +++ b/app/Notifications/ThreadDeletedNotification.php @@ -4,7 +4,6 @@ use App\Models\Thread; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification;