PHPackages                             aa-engineering/laravel-scheduled-reminders - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. aa-engineering/laravel-scheduled-reminders

ActiveLibrary[Queues &amp; Workers](/categories/queues)

aa-engineering/laravel-scheduled-reminders
==========================================

A Laravel package for scheduling and managing reminders with morphable relationships

1.1.0(1mo ago)0217—0%MITPHPPHP ^8.2|^8.3|^8.4

Since Oct 11Pushed 1mo agoCompare

[ Source](https://github.com/AA-ENGINEERING-Kft/laravel-scheduled-reminders)[ Packagist](https://packagist.org/packages/aa-engineering/laravel-scheduled-reminders)[ Docs](https://github.com/aa-engineering-kft/laravel-scheduled-reminders)[ RSS](/packages/aa-engineering-laravel-scheduled-reminders/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Laravel Scheduled Reminders
===========================

[](#laravel-scheduled-reminders)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b5f2e488a3d0daf057da931a9c487b96a70c3fff2398bc272e217395bb5b6b01/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61612d656e67696e656572696e672f6c61726176656c2d7363686564756c65642d72656d696e646572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aa-engineering/laravel-scheduled-reminders)[![Total Downloads](https://camo.githubusercontent.com/28c78ba33eb50816fbf838dc94d6da942e56db4f3bfa9e9d805042da6e230493/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61612d656e67696e656572696e672f6c61726176656c2d7363686564756c65642d72656d696e646572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aa-engineering/laravel-scheduled-reminders)

A Laravel package for scheduling and managing reminders with morphable relationships. Schedule notifications to be sent at specific times, attach them to any model, and track their delivery status.

Features
--------

[](#features)

- 📅 **Schedule reminders** for any date/time
- 🔗 **Polymorphic relationships** - attach reminders to any model
- 📊 **Track delivery status** - know when reminders were sent
- 🎯 **Source tracking** - link reminders to their originating models (tasks, events, etc.)
- 🧹 **Automatic pruning** - clean up old sent reminders
- 🎨 **Flexible data storage** - store custom data with each reminder
- ⚡ **Queue support** - send reminders via queue workers
- 🧪 **Fully tested** - comprehensive test suite included

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require aa-engineering/laravel-scheduled-reminders
```

Publish and run the migrations:

```
php artisan vendor:publish --tag="scheduled-reminders-migrations"
php artisan migrate
```

Optionally, publish the config file:

```
php artisan vendor:publish --tag="scheduled-reminders-config"
```

This is the contents of the published config file:

```
return [
    'prune_after_days' => env('REMINDERS_PRUNE_AFTER_DAYS', 30),
    'log_errors' => env('REMINDERS_LOG_ERRORS', true),
    'queue_connection' => env('REMINDERS_QUEUE_CONNECTION', null),
    'queue_name' => env('REMINDERS_QUEUE_NAME', 'default'),
];
```

Usage
-----

[](#usage)

### 1. Add the trait to your models

[](#1-add-the-trait-to-your-models)

Add the `Remindable` trait to any model that should receive reminders:

```
use AAEngineering\ScheduledReminders\Traits\Remindable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Remindable;

    // ...
}
```

### 2. Create a reminder

[](#2-create-a-reminder)

```
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']
);
```

### 3. Query reminders

[](#3-query-reminders)

```
// 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()) {
    // ...
}
```

### 4. Remove reminders

[](#4-remove-reminders)

```
// Remove reminders for a specific source
$user->removeReminder($task);

// Remove all pending reminders
$user->removePendingReminders();
```

### 5. Send reminders

[](#5-send-reminders)

Set up a scheduled task in your `routes/console.php`:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('reminders:send')->everyFiveMinutes();
```

Or manually send reminders:

```
# Send all pending reminders
php artisan reminders:send

# Limit the number of reminders to send
php artisan reminders:send --limit=100

# Dry run (see what would be sent without actually sending)
php artisan reminders:send --dry-run
```

### 6. Automatic pruning

[](#6-automatic-pruning)

Enable automatic pruning of sent reminders by adding to your `routes/console.php`:

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('model:prune')->daily();
```

Sent reminders older than the configured `prune_after_days` will be automatically deleted.

Advanced Usage
--------------

[](#advanced-usage)

### Custom Notification Data

[](#custom-notification-data)

You can store any custom data with your reminders:

```
$user->remindAt(
    notification: CustomNotification::class,
    source: $task,
    sendAt: now()->addHours(2),
    data: [
        'priority' => 'high',
        'category' => 'urgent',
        'custom_field' => 'value',
    ]
);
```

Access the data in your notification:

```
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']);
    }
}
```

### Notification Constructor Patterns

[](#notification-constructor-patterns)

The package supports flexible notification constructors. Here are all possible patterns:

#### 1. Constructor with Source Only

[](#1-constructor-with-source-only)

```
class SimpleNotification extends Notification
{
    public function __construct(
        public Model $source
    ) {}
}

// Usage
$user->remindAt(
    notification: SimpleNotification::class,
    source: $task,
    sendAt: now()->addDay()
);
```

#### 2. Constructor with Source and Data

[](#2-constructor-with-source-and-data)

```
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']
);
```

#### 3. Constructor with Data Only

[](#3-constructor-with-data-only)

```
class DataOnlyNotification extends Notification
{
    public function __construct(
        public array $data
    ) {}
}

// Usage
$user->remindAt(
    notification: DataOnlyNotification::class,
    sendAt: now()->addDay(),
    data: ['message' => 'Custom reminder']
);
```

#### 4. No Constructor Parameters

[](#4-no-constructor-parameters)

```
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()
);
```

#### 5. Constructor with Custom Parameters

[](#5-constructor-with-custom-parameters)

```
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
    ]
);
```

### Direct Model Access

[](#direct-model-access)

You can also work with the `Reminder` model directly:

```
use AAEngineering\ScheduledReminders\Models\Reminder;

// Find all pending reminders across the system
$pending = Reminder::whereNull('sent_at')
    ->where('send_at', '
