complete story 8.8 with qa tests
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\TimelineUpdate;
|
||||
use Illuminate\Mail\Mailables\Content;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
class TimelineUpdateEmail extends BaseMailable
|
||||
{
|
||||
public function __construct(
|
||||
public TimelineUpdate $update
|
||||
) {
|
||||
$this->locale = $this->update->timeline->user->preferred_language ?? 'ar';
|
||||
}
|
||||
|
||||
public function envelope(): Envelope
|
||||
{
|
||||
$caseName = $this->update->timeline->case_name;
|
||||
|
||||
$subject = $this->locale === 'ar'
|
||||
? "تحديث على قضيتك: {$caseName}"
|
||||
: "Update on your case: {$caseName}";
|
||||
|
||||
return new Envelope(
|
||||
subject: $subject,
|
||||
);
|
||||
}
|
||||
|
||||
public function content(): Content
|
||||
{
|
||||
return new Content(
|
||||
markdown: "emails.timeline.update.{$this->locale}",
|
||||
with: [
|
||||
'update' => $this->update,
|
||||
'timeline' => $this->update->timeline,
|
||||
'user' => $this->update->timeline->user,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Enums\TimelineStatus;
|
||||
use App\Mail\TimelineUpdateEmail;
|
||||
use App\Models\TimelineUpdate;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class TimelineUpdateObserver
|
||||
{
|
||||
public function created(TimelineUpdate $update): void
|
||||
{
|
||||
// Only send for active timelines
|
||||
if ($update->timeline->status !== TimelineStatus::Active) {
|
||||
return;
|
||||
}
|
||||
|
||||
$client = $update->timeline->user;
|
||||
|
||||
Mail::to($client->email)->queue(
|
||||
new TimelineUpdateEmail($update)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ namespace App\Providers;
|
||||
|
||||
use App\Listeners\LogFailedLoginAttempt;
|
||||
use App\Models\Consultation;
|
||||
use App\Models\TimelineUpdate;
|
||||
use App\Observers\ConsultationObserver;
|
||||
use App\Observers\TimelineUpdateObserver;
|
||||
use Illuminate\Auth\Events\Failed;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -27,5 +29,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
Event::listen(Failed::class, LogFailedLoginAttempt::class);
|
||||
|
||||
Consultation::observe(ConsultationObserver::class);
|
||||
TimelineUpdate::observe(TimelineUpdateObserver::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user