complete story 3.5 with qa test
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<?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 BookingApproved extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Consultation $consultation,
|
||||
public string $icsContent,
|
||||
public ?string $paymentInstructions = null
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 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.booking-approved', [
|
||||
'consultation' => $this->consultation,
|
||||
'paymentInstructions' => $this->paymentInstructions,
|
||||
'locale' => $locale,
|
||||
'user' => $notifiable,
|
||||
]);
|
||||
|
||||
// Attach .ics file if available
|
||||
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 Booking Approved';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'booking_approved',
|
||||
'consultation_id' => $this->consultation->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?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 BookingRejected extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public Consultation $consultation,
|
||||
public ?string $rejectionReason = null
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 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.booking-rejected', [
|
||||
'consultation' => $this->consultation,
|
||||
'rejectionReason' => $this->rejectionReason,
|
||||
'locale' => $locale,
|
||||
'user' => $notifiable,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the subject based on locale.
|
||||
*/
|
||||
private function getSubject(string $locale): string
|
||||
{
|
||||
return $locale === 'ar'
|
||||
? 'بخصوص طلب الاستشارة الخاص بك'
|
||||
: 'Regarding Your Consultation Request';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
'type' => 'booking_rejected',
|
||||
'consultation_id' => $this->consultation->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user