49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\IntegrationRequest;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class NewIntegrationRequestNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(public IntegrationRequest $integrationRequest)
|
|
{
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return ['database', 'mail'];
|
|
}
|
|
|
|
public function toMail(object $notifiable): MailMessage
|
|
{
|
|
$agentName = $this->integrationRequest->agent->first_name . ' ' . $this->integrationRequest->agent->last_name;
|
|
$type = $this->integrationRequest->type === 'onboarding' ? 'Arrivée' : 'Départ';
|
|
$createdBy = $this->integrationRequest->agent->creator->name ?? 'Un prescripteur';
|
|
|
|
return (new MailMessage)
|
|
->subject("Nouvelle fiche agent : {$agentName}")
|
|
->greeting("Bonjour {$notifiable->name},")
|
|
->line("Une nouvelle fiche agent de type **{$type}** a été initiée par **{$createdBy}**.")
|
|
->line("Agent concerné : **{$agentName}**")
|
|
->line("Cette demande est en attente de validation RH.")
|
|
->action('Voir la demande', route('integrations.show', $this->integrationRequest))
|
|
->line('Merci de traiter cette demande.');
|
|
}
|
|
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'integration_request_id' => $this->integrationRequest->id,
|
|
'message' => "Nouvelle fiche agent pour {$this->integrationRequest->agent->first_name}",
|
|
'type' => 'new_request',
|
|
];
|
|
}
|
|
}
|