46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Notifications;
|
||
|
|
|
||
|
|
use App\Models\Task;
|
||
|
|
use Illuminate\Bus\Queueable;
|
||
|
|
use Illuminate\Notifications\Notification;
|
||
|
|
|
||
|
|
class TaskStatusChangedNotification extends Notification
|
||
|
|
{
|
||
|
|
use Queueable;
|
||
|
|
|
||
|
|
public function __construct(public Task $task, public string $oldStatus) {}
|
||
|
|
|
||
|
|
public function via($notifiable): array
|
||
|
|
{
|
||
|
|
return ['database'];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toArray($notifiable): array
|
||
|
|
{
|
||
|
|
$label = [
|
||
|
|
'pending' => 'pendiente',
|
||
|
|
'in_progress' => 'en progreso',
|
||
|
|
'completed' => 'completada',
|
||
|
|
'cancelled' => 'cancelada',
|
||
|
|
][$this->task->status] ?? $this->task->status;
|
||
|
|
|
||
|
|
$oldLabel = [
|
||
|
|
'pending' => 'pendiente',
|
||
|
|
'in_progress' => 'en progreso',
|
||
|
|
'completed' => 'completada',
|
||
|
|
'cancelled' => 'cancelada',
|
||
|
|
][$this->oldStatus] ?? $this->oldStatus;
|
||
|
|
|
||
|
|
return [
|
||
|
|
'type' => 'task_status_changed',
|
||
|
|
'task_id' => $this->task->id,
|
||
|
|
'project_id' => $this->task->project_id,
|
||
|
|
'old_status' => $this->oldStatus,
|
||
|
|
'new_status' => $this->task->status,
|
||
|
|
'message' => "La tarea '{$this->task->title}' cambió de {$oldLabel} a {$label}",
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|