Skip to content

Commit

Permalink
add broadcast message
Browse files Browse the repository at this point in the history
  • Loading branch information
Bagas Udi Sahsangka committed Sep 18, 2021
1 parent 8c3ab57 commit 08e682f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 19 deletions.
15 changes: 13 additions & 2 deletions app/Notifications/GateInNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Notifications;

use App\Models\GateIn;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;

class GateInNotification extends Notification implements ShouldQueue
{
Expand All @@ -31,7 +31,7 @@ public function __construct($message)
*/
public function via($notifiable)
{
return ['database'];
return ['database', 'broadcast'];
}

/**
Expand All @@ -46,4 +46,15 @@ public function toArray($notifiable)
'message' => $this->message
];
}

/**
* Get the broadcastable representation of the notification.
*
* @param mixed $notifiable
* @return BroadcastMessage
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage(['message' => $this->message]);
}
}
21 changes: 17 additions & 4 deletions app/Notifications/KameraErrorNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;

class KameraErrorNotification extends Notification implements ShouldQueue
{
use Queueable;

public $kamera;

public $message;

/**
* Create a new notification instance.
*
Expand All @@ -21,6 +24,7 @@ class KameraErrorNotification extends Notification implements ShouldQueue
public function __construct(Kamera $kamera)
{
$this->kamera = $kamera;
$this->message = "Kamera {$this->kamera->nama} gagal mengambil snapshot";
}

/**
Expand All @@ -31,7 +35,7 @@ public function __construct(Kamera $kamera)
*/
public function via($notifiable)
{
return ['database'];
return ['database', 'broadcast'];
}

/**
Expand All @@ -42,8 +46,17 @@ public function via($notifiable)
*/
public function toArray($notifiable)
{
return [
'message' => "Kamera {$this->kamera->nama} gagal mengambil snapshot"
];
return ['message' => $this->message];
}

/**
* Get the broadcastable representation of the notification.
*
* @param mixed $notifiable
* @return BroadcastMessage
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage(['message' => $this->message]);
}
}
23 changes: 16 additions & 7 deletions app/Notifications/PrintStrukFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;

class PrintStrukFailedNotification extends Notification implements ShouldQueue
{
use Queueable;

public $parkingTransaction;

public $error;
public $message;

/**
* Create a new notification instance.
Expand All @@ -23,8 +24,7 @@ class PrintStrukFailedNotification extends Notification implements ShouldQueue
public function __construct(ParkingTransaction $parkingTransaction, $error)
{
$this->parkingTransaction = $parkingTransaction;

$this->error = $error;
$this->message = "Gagal print tiket di {$this->parkingTransaction->gateIn->nama}. {$error}";
}

/**
Expand All @@ -35,7 +35,7 @@ public function __construct(ParkingTransaction $parkingTransaction, $error)
*/
public function via($notifiable)
{
return ['database'];
return ['database', 'broadcast'];
}

/**
Expand All @@ -46,8 +46,17 @@ public function via($notifiable)
*/
public function toArray($notifiable)
{
return [
'message' => "Gagal print tiket di {$this->parkingTransaction->gateIn->nama}. {$this->error}",
];
return ['message' => $this->message];
}

/**
* Get the broadcastable representation of the notification.
*
* @param mixed $notifiable
* @return BroadcastMessage
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage(['message' => $this->message]);
}
}
22 changes: 16 additions & 6 deletions app/Notifications/PrintTicketFailedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\BroadcastMessage;

class PrintTicketFailedNotification extends Notification implements ShouldQueue
{
use Queueable;

public $parkingTransaction;

public $error;
public $message;

/**
* Create a new notification instance.
Expand All @@ -24,7 +25,7 @@ public function __construct(ParkingTransaction $parkingTransaction, $error)
{
$this->parkingTransaction = $parkingTransaction;

$this->error = $error;
$this->message = "Pengunjung di {$this->parkingTransaction->gateIn->nama} gagal print tiket. Informasikan nomor barcode kepada pengunjung. {$this->parkingTransaction->nomor_barcode}. {$error}";
}

/**
Expand All @@ -35,7 +36,7 @@ public function __construct(ParkingTransaction $parkingTransaction, $error)
*/
public function via($notifiable)
{
return ['database'];
return ['database', 'broadcast'];
}

/**
Expand All @@ -46,8 +47,17 @@ public function via($notifiable)
*/
public function toArray($notifiable)
{
return [
'message' => "Pengunjung di {$this->parkingTransaction->gateIn->nama} gagal print tiket. Informasikan nomor barcode kepada pengunjung. {$this->parkingTransaction->nomor_barcode}. {$this->error}",
];
return ['message' => $this->message];
}

/**
* Get the broadcastable representation of the notification.
*
* @param mixed $notifiable
* @return BroadcastMessage
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage(['message' => $this->message]);
}
}

0 comments on commit 08e682f

Please sign in to comment.