use AAEngineering\ScheduledReminders\Traits\Remindable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Remindable;
// ...
}
use App\Notifications\TaskDueNotification;
$user = User::find(1);
$task = Task::find(1);
// Schedule a reminder for tomorrow
$user->remindAt(
notification: TaskDueNotification::class,
source: $task,
sendAt: now()->addDay(),
data: ['custom' => 'data']
);
// Get all reminders
$allReminders = $user->reminders;
// Get pending reminders (due but not sent)
$pendingReminders = $user->pendingReminders;
// Get future reminders (scheduled for later)
$futureReminders = $user->futureReminders;
// Get sent reminders
$sentReminders = $user->sentReminders;
// Check if user has pending reminders
if ($user->hasPendingReminders()) {
// ...
}
// Remove reminders for a specific source
$user->removeReminder($task);
// Remove all pending reminders
$user->removePendingReminders();
use Illuminate\Support\Facades\Schedule;
Schedule::command('reminders:send')->everyFiveMinutes();
use Illuminate\Support\Facades\Schedule;
Schedule::command('model:prune')->daily();
class CustomNotification extends Notification
{
public function __construct(
public Model $source,
public array $data
) {}
public function toMail($notifiable)
{
$priority = $this->data['priority'] ?? 'normal';
return (new MailMessage)
->subject("Task Reminder - Priority: {$priority}")
->line($this->data['custom_field']);
}
}
class SimpleNotification extends Notification
{
public function __construct(
public Model $source
) {}
}
// Usage
$user->remindAt(
notification: SimpleNotification::class,
source: $task,
sendAt: now()->addDay()
);
class DataNotification extends Notification
{
public function __construct(
public Model $source,
public array $data
) {}
}
// Usage
$user->remindAt(
notification: DataNotification::class,
source: $task,
sendAt: now()->addDay(),
data: ['priority' => 'high']
);
class DataOnlyNotification extends Notification
{
public function __construct(
public array $data
) {}
}
// Usage
$user->remindAt(
notification: DataOnlyNotification::class,
sendAt: now()->addDay(),
data: ['message' => 'Custom reminder']
);
class StaticNotification extends Notification
{
// No constructor needed
public function toMail($notifiable)
{
return (new MailMessage)
->line('Static reminder message');
}
}
// Usage
$user->remindAt(
notification: StaticNotification::class,
sendAt: now()->addDay()
);
class CustomNotification extends Notification
{
public function __construct(
public string $title,
public int $priority = 1
) {}
}
// Usage - Custom parameters are passed via data array
$user->remindAt(
notification: CustomNotification::class,
sendAt: now()->addDay(),
data: [
'title' => 'Important Task',
'priority' => 5
]
);
use AAEngineering\ScheduledReminders\Models\Reminder;
// Find all pending reminders across the system
$pending = Reminder::whereNull('sent_at')
->where('send_at', '<=', now())
->get();
// Find reminders for a specific source
$taskReminders = Reminder::where('source_type', Task::class)
->where('source_id', $taskId)
->get();
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
class TaskDueNotification extends Notification implements ShouldQueue
{
// This notification will be queued when sent
}