58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\CollectionLog;
|
|
use App\Notifications\Concerns\RoutesByPreferences;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class WasteCollected extends Notification
|
|
{
|
|
use Queueable, RoutesByPreferences;
|
|
|
|
public const PREF_KEY = 'waste_collected';
|
|
|
|
public function __construct(public readonly CollectionLog $log) {}
|
|
|
|
public function toArray(mixed $notifiable): array
|
|
{
|
|
$time = $this->log->scanned_at?->format('h:i A') ?? now()->format('h:i A');
|
|
$wasteTypeStr = $this->log->waste_type ? strtolower($this->log->waste_type) . ' ' : '';
|
|
|
|
return [
|
|
'type' => 'waste.collected',
|
|
'collection_log_id' => $this->log->id,
|
|
'message' => "Your {$wasteTypeStr}waste was successfully collected at {$time}.",
|
|
'action_label' => 'View History',
|
|
'action_url' => '/collections',
|
|
];
|
|
}
|
|
|
|
public function toSms(mixed $notifiable): array
|
|
{
|
|
$time = $this->log->scanned_at?->format('h:i A') ?? now()->format('h:i A');
|
|
$wasteTypeStr = $this->log->waste_type ? strtolower($this->log->waste_type) . ' ' : '';
|
|
|
|
return [
|
|
'to' => $notifiable->phone,
|
|
'message' => "Verde: Your {$wasteTypeStr}waste was successfully collected at {$time}.",
|
|
];
|
|
}
|
|
|
|
public function toPush(mixed $notifiable): array
|
|
{
|
|
$time = $this->log->scanned_at?->format('h:i A') ?? now()->format('h:i A');
|
|
$wasteTypeStr = $this->log->waste_type ? strtolower($this->log->waste_type) . ' ' : '';
|
|
|
|
return [
|
|
'title' => 'Waste Collected',
|
|
'body' => "Your {$wasteTypeStr}waste was successfully collected at {$time}.",
|
|
'data' => [
|
|
'type' => 'waste.collected',
|
|
'collection_log_id' => (string) $this->log->id,
|
|
],
|
|
];
|
|
}
|
|
}
|