complete story 3.7 with qa test
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Consultation;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class ConsultationCancelled extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Consultation $consultation
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$locale = $notifiable->preferred_language ?? 'ar';
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($this->getSubject($locale))
|
||||
->view('emails.consultation-cancelled', [
|
||||
'consultation' => $this->consultation,
|
||||
'locale' => $locale,
|
||||
'user' => $notifiable,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subject based on locale.
|
||||
*/
|
||||
private function getSubject(string $locale): string
|
||||
{
|
||||
return $locale === 'ar'
|
||||
? 'تم إلغاء موعد استشارتك'
|
||||
: 'Your Consultation Has Been Cancelled';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'consultation_cancelled',
|
||||
'consultation_id' => $this->consultation->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Consultation;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class ConsultationRescheduled extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Consultation $consultation,
|
||||
public Carbon $oldDate,
|
||||
public string $oldTime,
|
||||
public string $icsContent
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$locale = $notifiable->preferred_language ?? 'ar';
|
||||
|
||||
$message = (new MailMessage)
|
||||
->subject($this->getSubject($locale))
|
||||
->view('emails.consultation-rescheduled', [
|
||||
'consultation' => $this->consultation,
|
||||
'oldDate' => $this->oldDate,
|
||||
'oldTime' => $this->oldTime,
|
||||
'locale' => $locale,
|
||||
'user' => $notifiable,
|
||||
]);
|
||||
|
||||
// Attach new .ics file
|
||||
if (! empty($this->icsContent)) {
|
||||
$message->attachData(
|
||||
$this->icsContent,
|
||||
'consultation.ics',
|
||||
['mime' => 'text/calendar']
|
||||
);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subject based on locale.
|
||||
*/
|
||||
private function getSubject(string $locale): string
|
||||
{
|
||||
return $locale === 'ar'
|
||||
? 'تم إعادة جدولة موعد استشارتك'
|
||||
: 'Your Consultation Has Been Rescheduled';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'consultation_rescheduled',
|
||||
'consultation_id' => $this->consultation->id,
|
||||
'old_date' => $this->oldDate->toDateString(),
|
||||
'old_time' => $this->oldTime,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user