feature(send notification for report status): send mail to broker and user when admin resolves/rejects the reports

This commit is contained in:
kusowl 2026-02-02 19:33:25 +05:30
parent d7c06c38a6
commit 2fecd52d7e
4 changed files with 154 additions and 2 deletions

View File

@ -5,6 +5,8 @@
use App\Enums\ReportStatus; use App\Enums\ReportStatus;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Report; use App\Models\Report;
use App\Notifications\ReportResolvedNotificationToBroker;
use App\Notifications\ReportRejectedNotificationToUser;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class ReportController extends Controller class ReportController extends Controller
@ -27,9 +29,13 @@ public function resolve(Report $report)
$report->status = ReportStatus::Resolved; $report->status = ReportStatus::Resolved;
$report->save(); $report->save();
$report->user->notify(new ReportRejectedNotificationToUser($report->deals()->first()->title, false));
$report->deals()->first()->broker->notify(new ReportResolvedNotificationToBroker($report->deals()->first()->title,
false));
return back()->with('success', 'Report resolved successfully.'); return back()->with('success', 'Report resolved successfully.');
} catch (\Throwable $e) { } catch (\Throwable $e) {
\Log::error('Error resolving report', [$report->id, $e->getMessage(), $e->getTraceAsString()]); \Log::error('Error resolving report', [$report->id, $e->getMessage()]);
return back()->with('error', 'Something went wrong.'); return back()->with('error', 'Something went wrong.');
} }
@ -41,9 +47,11 @@ public function reject(Report $report)
$report->status = ReportStatus::Rejected; $report->status = ReportStatus::Rejected;
$report->save(); $report->save();
$report->user->notify(new ReportRejectedNotificationToUser($report->deals()->first()->title));
return back()->with('success', 'Report Rejected successfully.'); return back()->with('success', 'Report Rejected successfully.');
} catch (\Throwable $e) { } catch (\Throwable $e) {
\Log::error('Error rejecting report', [$report->id, $e->getMessage(), $e->getTraceAsString()]); \Log::error('Error rejecting report', [$report->id, $e->getMessage()]);
return back()->with('error', 'Something went wrong.'); return back()->with('error', 'Something went wrong.');
} }
@ -56,6 +64,11 @@ public function removeContent(Report $report)
{ {
try { try {
DB::transaction(function () use ($report) { DB::transaction(function () use ($report) {
$report->user->notify(new ReportRejectedNotificationToUser($report->deals()->first()->title, true));
$report->deals()->first()->broker->notify(new ReportResolvedNotificationToBroker($report->deals()->first()->title,
true));
$deal = $report->deals()->first(); $deal = $report->deals()->first();
$deal->active = false; $deal->active = false;
$report->status = ReportStatus::Resolved; $report->status = ReportStatus::Resolved;

View File

@ -0,0 +1,44 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ReportRejectedNotificationToUser extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
private readonly string $dealTitle,
) {
}
public function via($notifiable): array
{
return ['mail'];
}
public function toMail($notifiable): MailMessage
{
return (new MailMessage)
->subject('Update on Your Recent Report: '.$this->dealTitle)
->greeting('Hello!')
->line("Thank you for helping us maintain the integrity of our marketplace.")
->line("We have completed our review of the deal you reported: **{$this->dealTitle}**.")
->line("Based on our moderation policy, we have rejected your report.")
->action('View Marketplace', route('explore'))
->line('Your feedback helps make our community a safer place for everyone.');
}
public function toArray($notifiable): array
{
return [
'report_outcome' => $this->isContentRemoved ? 'violation_confirmed' : 'no_violation_found',
'deal_title' => $this->dealTitle
];
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ReportResolvedNotificationToBroker extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
private readonly string $dealTitle,
private readonly bool $isContentRemoved
) {
}
public function via($notifiable): array
{
return ['mail'];
}
public function toMail($notifiable): MailMessage
{
$status = $this->isContentRemoved
? 'has been removed following a policy review.'
: 'has been reviewed and remains active.';
return (new MailMessage)
->subject('Update Regarding Your Reported Deal: '.$this->dealTitle)
->greeting('Hello!')
->line("We are writing to inform you that the report regarding your deal, **{$this->dealTitle}**, has been resolved.")
->line("Our moderation team has completed their review, and the content {$status}")
->action('View My Deals', route('broker.dashboard')) // Adjusted for your UMS/Project structure
->line('Thank you for being a part of our marketplace.');
}
public function toArray($notifiable): array
{
return [
'deal_title' => $this->dealTitle,
'action_taken' => $this->isContentRemoved ? 'removed' : 'kept',
];
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ReportResolvedNotificationToUser extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
private readonly string $dealTitle,
private readonly bool $isContentRemoved
) {
}
public function via($notifiable): array
{
return ['mail'];
}
public function toMail($notifiable): MailMessage
{
$outcome = $this->isContentRemoved
? 'has been removed following our investigation.'
: 'will remain active as it was found to be in compliance with our guidelines.';
return (new MailMessage)
->subject('Update on Your Recent Report: '.$this->dealTitle)
->greeting('Hello!')
->line("Thank you for helping us maintain the integrity of our marketplace.")
->line("We have completed our review of the deal you reported: **{$this->dealTitle}**.")
->line("Based on our moderation policy, the content {$outcome}")
->action('View Marketplace', route('explore'))
->line('Your feedback helps make our community a safer place for everyone.');
}
public function toArray($notifiable): array
{
return [
'report_outcome' => $this->isContentRemoved ? 'violation_confirmed' : 'no_violation_found',
'deal_title' => $this->dealTitle
];
}
}