Skip to content

Instantly share code, notes, and snippets.

@hotmeteor
Last active February 25, 2020 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotmeteor/a35a61fa5600f4a880a28640753acff5 to your computer and use it in GitHub Desktop.
Save hotmeteor/a35a61fa5600f4a880a28640753acff5 to your computer and use it in GitHub Desktop.
Handling delayed notifications in Laravel, pt. 2
<?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
}
}
@gladtoseeuhappy
Copy link

subDay is not undefined, can u fix this??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment