Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/Http/Controllers/Forum/ThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down
33 changes: 33 additions & 0 deletions app/Notifications/ThreadDeletedNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Notifications;

use App\Models\Thread;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ThreadDeletedNotification extends Notification
{
use Queueable;

public function __construct(
public Thread $thread,
public ?string $reason = null,
) {
}

public function via($notifiable)
{
return ['mail'];
}

public function toMail($notifiable)
{
return (new MailMessage)
->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');
}
}
1 change: 1 addition & 0 deletions resources/views/components/threads/thread-menu.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ class="absolute top-12 right-1 flex flex-col bg-white rounded shadow w-48"
title="Delete Thread"
>
<p>Are you sure you want to delete this thread and its replies? This cannot be undone.</p>
<x-forms.inputs.textarea name="reason" label="Reason" placeholder="Reason... (Optional)" />
</x-modal>
@endcanany