69 lines
1.9 KiB
PHP
69 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Document;
|
|
use App\Models\User;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class ApprovalRequestNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
protected $document;
|
|
protected $requester;
|
|
|
|
/**
|
|
* Create a new notification instance.
|
|
*/
|
|
public function __construct(Document $document, User $requester)
|
|
{
|
|
$this->document = $document;
|
|
$this->requester = $requester;
|
|
}
|
|
|
|
/**
|
|
* Get the notification's delivery channels.
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['mail', 'database'];
|
|
}
|
|
|
|
/**
|
|
* Get the mail representation of the notification.
|
|
*/
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
return (new MailMessage)
|
|
->subject('Solicitud de aprobación de documento')
|
|
->greeting('Hola ' . $notifiable->name . '!')
|
|
->line($this->requester->name . ' ha solicitado tu aprobación para el documento:')
|
|
->line('**Documento:** ' . $this->document->name)
|
|
->action('Revisar Documento', route('documents.show', $this->document))
|
|
->line('Fecha límite: ' . $this->document->due_date->format('d/m/Y'))
|
|
->line('Gracias por usar nuestro sistema!');
|
|
}
|
|
|
|
/**
|
|
* Get the array representation of the notification.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'type' => 'approval-request',
|
|
'document_id' => $this->document->id,
|
|
'requester_id' => $this->requester->id,
|
|
'message' => 'Nueva solicitud de aprobación para: ' . $this->document->name,
|
|
'link' => route('documents.show', $this->document)
|
|
];
|
|
}
|
|
}
|