Skip to content

Commit

Permalink
feat: event subscriber is created for the model report, and created n…
Browse files Browse the repository at this point in the history
…otification for report status changes.
  • Loading branch information
sriramkanakam87 committed Apr 18, 2024
1 parent 02ba9b0 commit 5c49664
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/Listeners/ReportEventSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Events\Dispatcher;
use App\Events\ReportStatusChanged;
use App\Models\User;
use App\Notifications\ReportStatusChangedNotification;


class ReportEventSubscriber
{
/**
* Create the event listener.
*/

public $ReportOwner;

public function __construct()
{
//
}

/**
* Handle the event.
*/
public function handleReportStatusChanged(ReportStatusChanged $event): void
{
$ReportOwner = User::find($event->report->user_id);
$ReportOwner->notify(new ReportStatusChangedNotification($event));
}

public function subscribe(Dispatcher $events): array
{
return [
ReportStatusChanged::class => 'handleReportStatusChanged',
];
}
}
54 changes: 54 additions & 0 deletions app/Notifications/ReportStatusChangedNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class ReportStatusChangedNotification extends Notification implements ShouldQueue
{
use Queueable;

/**
* Create a new notification instance.
*/
public function __construct()
{
//
}

/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['mail'];
}

/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}

/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
];
}
}

0 comments on commit 5c49664

Please sign in to comment.