Last active
February 25, 2020 07:49
-
-
Save hotmeteor/a35a61fa5600f4a880a28640753acff5 to your computer and use it in GitHub Desktop.
Handling delayed notifications in Laravel, pt. 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Notifications; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Notifications\Notification; | |
use Illuminate\Queue\SerializesModels; | |
class AppointmentReminder extends Notification implements ShouldQueue | |
{ | |
use Queueable, SerializesModels; | |
public $appointment; | |
public function __construct(Appointment $appointment) | |
{ | |
$this->appointment = $appointment; | |
$this->delay($appointment->start_date_time)->subDay(1); | |
} | |
public function via($notifiable) | |
{ | |
if($this->dontSend($notifiable)) { | |
return []; | |
} | |
return ['mail']; | |
} | |
public function dontSend($notifiable) | |
{ | |
return $this->appointment->status === 'cancelled'; | |
} | |
public function toMail() | |
{ | |
// Return mail contents | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
subDay
is not undefined, can u fix this??