PHPackages                             neelkanthk/laravel-schedulable - 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. [Database &amp; ORM](/categories/database)
4. /
5. neelkanthk/laravel-schedulable

ActiveLaravel-package[Database &amp; ORM](/categories/database)

neelkanthk/laravel-schedulable
==============================

A Laravel package to add scheduling capability in Eloquent models.

1.1.0(5y ago)11432812MITPHPPHP &gt;=7.2

Since Oct 14Pushed 4y ago3 watchersCompare

[ Source](https://github.com/neelkanthk/laravel-schedulable)[ Packagist](https://packagist.org/packages/neelkanthk/laravel-schedulable)[ RSS](/packages/neelkanthk-laravel-schedulable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (8)Used By (0)

[![Laravel Schedulable Logo](https://github.com/neelkanthk/repo_logos/raw/master/LaravelSchedulable_small.png?raw=true)](https://github.com/neelkanthk/repo_logos/blob/master/LaravelSchedulable_small.png?raw=true)

[![](https://camo.githubusercontent.com/ae9069f708e188baf5d30f0fb5e63817b6104147eafddcd6dc56cf96c57d8635/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/ae9069f708e188baf5d30f0fb5e63817b6104147eafddcd6dc56cf96c57d8635/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c653f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/cb46069ac721ef0cb69cdde50c658abe3c4cf8d3bcc285065dc46fec96e5268a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c652e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/cb46069ac721ef0cb69cdde50c658abe3c4cf8d3bcc285065dc46fec96e5268a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c652e7376673f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/3d574f9beaff1dff3f8892b94b1138e994ce0f5c0b5ef65108e1ee92e27775a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d253345253344362e302d7265643f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/3d574f9beaff1dff3f8892b94b1138e994ce0f5c0b5ef65108e1ee92e27775a7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d253345253344362e302d7265643f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/5d20108400145d6c39ba9099f98a890459a70468bfb62692eae96b2ba9b1ee8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d50617373696e672d677265656e3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/5d20108400145d6c39ba9099f98a890459a70468bfb62692eae96b2ba9b1ee8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54657374732d50617373696e672d677265656e3f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/9b4c5ba6bcb10276ec073f5e5c646abb4fe8f6db6301e5e5a96a65ffa594f90a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/9b4c5ba6bcb10276ec073f5e5c646abb4fe8f6db6301e5e5a96a65ffa594f90a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c653f7374796c653d666f722d7468652d6261646765)[![](https://camo.githubusercontent.com/5b49d7390a1be21e052ac2ff08fae9b8d7e0abc3e24eca414d28ee246010621f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c653f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/5b49d7390a1be21e052ac2ff08fae9b8d7e0abc3e24eca414d28ee246010621f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e65656c6b616e74686b2f6c61726176656c2d7363686564756c61626c653f7374796c653d666f722d7468652d6261646765)

Laravel Schedulable [![Twitter](https://camo.githubusercontent.com/5879fb90d77180f3c380216527525b887d7a02cfb18c5b1b07bdab434f605a4f/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c3f7374796c653d736f6369616c2675726c3d68747470732533412532462532466769746875622e636f6d2532466e65656c6b616e74686b2532466c61726176656c2d7363686564756c61626c65)](https://twitter.com/intent/tweet?text=Laravel%20Schedulable:&url=https%3A%2F%2Fgithub.com%2Fneelkanthk%2Flaravel-schedulable)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-schedulable-)

Schedule and Unschedule any eloquent model elegantly without cron job.
----------------------------------------------------------------------

[](#schedule-and-unschedule-any-eloquent-model-elegantly-without-cron-job)

Salient Features:
-----------------

[](#salient-features)

1. **Turn any Eloquent Model into a schedulable** one by using `Schedulable` trait in the model.
2. **Schedule Models to a time in future** and they will be returned in query results at specified date and time.
3. **Reschedule** and **Unschedule** at any time using simple methods.
4. Hook into the model's life cycle via **custom model events** provided by the package.
5. **Override the default column name** and use your own custom column name.

***Some example use cases when this package can be useful:***

1. A Blog type application which allows bloggers to schedule their post to go public on a future date and time.
2. An E-commerce website where the items in the inventory can be added at any time from the admin panel but they can be scheduled to be made available to the customers at a particular date and time.

Minimum Requirements
--------------------

[](#minimum-requirements)

1. Laravel 6.0
2. PHP 7.2

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

[](#installation)

```
composer require neelkanthk/laravel-schedulable
```

Usage
-----

[](#usage)

#### 1. Create a migration to add `schedule_at` column in any table using package's `scheduleAt();` method which creates a column with name `schedule_at`.

[](#1-create-a-migration-to-add-schedule_at-column-in-any-table-using-packages-scheduleat-method-which-creates-a-column-with-name-schedule_at)

#### *NOTE:* If you want to use any other column name then simply use the `$table->timestamp('column_name');` method as shown below in examples.

[](#note-if-you-want-to-use-any-other-column-name-then-simply-use-the-table-timestampcolumn_name-method-as-shown-below-in-examples)

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddScheduleAtColumnInPosts extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->scheduleAt(); //Using default schedule_at column
			//or
            $table->timestamp('publish_at', 0)->nullable(); //Using custom column name
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('posts', function (Blueprint $table) {
            $table->dropColumn('schedule_at'); //Using default schedule_at column
            //or
            $table->dropColumn('publish_at'); //Using custom column name
        });
    }
}
```

#### 2. Use the `Neelkanth\Laravel\Schedulable\Traits\Schedulable` trait in any Model.

[](#2-use-the-neelkanthlaravelschedulabletraitsschedulable-trait-in-any-model)

#### *NOTE:* If you have used a custom column name in the migration then you have to specify that column in the Model as shown below.

[](#note-if-you-have-used-a-custom-column-name-in-the-migration-then-you-have-to-specify-that-column-in-the-model-as-shown-below)

```
use Illuminate\Database\Eloquent\Model;
use Neelkanth\Laravel\Schedulable\Traits\Schedulable;

class Post extends Model
{
    use Schedulable;

    const SCHEDULE_AT = "publish_at"; //Specify the custom column name
}
```

Usage
-----

[](#usage-1)

### 1. Scheduling a model

[](#1-scheduling-a-model)

```
$scheduleAt = Carbon::now()->addDays(10); //Carbon is just an example. You can pass any object which is implementing DateTimeInterface.
$post = new App\Post();
//Add values to other attributes
$post->scheduleWithoutSaving($scheduleAt); // Modifies the schedule_at attribute and returns the current model object without saving it.
$post->schedule($scheduleAt); //Saves the model in the database and returns boolean true or false
```

### 2. Unscheduling a model

[](#2-unscheduling-a-model)

```
$post = App\Post::find(1);
$post->unscheduleWithoutSaving(); // Modifies the schedule_at attribute and returns the current model object without saving it.
$post->unschedule(); //Saves the model in the database and returns boolean true or false
```

### 3. Events and Observers

[](#3-events-and-observers)

The package provides four model events and Observer methods which the developers can use to hook in the model's lifecycle.

The `schedule()` method fires two events namely `scheduling` before saving the model and `scheduled` after saving the model.

The `unschedule()` method fires two events namely `unscheduling` before saving the model and `unscheduled` after saving the model.

The above events can be caught in the Observer class as follows:

```
namespace App\Observers;

use App\Post;

class PostObserver
{
    public function scheduling(Post $post)
    {
        //
    }

    public function scheduled(Post $post)
    {
        //
    }

    public function unscheduling(Post $post)
    {
        //
    }

    public function unscheduled(Post $post)
    {
        //
    }
}
```

### 4. Fetching data using queries

[](#4-fetching-data-using-queries)

We will assume below posts table as reference to the following examples:

idtitlecreated\_atupdated\_atschedule\_at1Toy Story 12020-06-01 12:15:00NULLNULL2Toy Story 22020-08-02 16:10:12NULL2020-08-10 10:10:003Toy Story 32020-10-10 10:00:10NULL2021-12-20 00:00:004Terminator 22020-10-11 00:00:00NULL2021-11-12 15:10:17**For the following examples, Suppose the current timestamp is 2020-10-18 00:00:00.**

#### 1. Default

[](#1-default)

By default all those models are fetched in which the `schedule_at` column is having `NULL` value or a timestamp less than or equal to the current timestamp.

So a eloquent query

```
$posts = App\Post::get();
```

will return Toy Story 1 and Toy Story 2

#### 2. Retrieving scheduled models in addition to the normal.

[](#2-retrieving-scheduled-models-in-addition-to-the-normal)

To retrieve scheduled models in addition to the normal models, use the `withScheduled()` method.

```
$posts = App\Post::withScheduled()->get();
```

The above query will return all the four rows in the above table.

#### 3. Retrieving only scheduled models without normal.

[](#3-retrieving-only-scheduled-models-without-normal)

To retrieve only scheduled models use the `onlyScheduled()` method.

```
$posts = App\Post::onlyScheduled()->get();
```

The above query will return Toy Story 3 and Terminator 2.

#### 4. Do not apply any functionality provided by `Schedulable`.

[](#4-do-not-apply-any-functionality-provided-by-schedulable)

In some cases you may not want to apply the `Schedulable` trait at all. In those cases use the `withoutGlobalScope()` method in your query.

```
use Neelkanth\Laravel\Schedulable\Scopes\SchedulableScope;

$posts = App\Post::withoutGlobalScope(SchedulableScope::class)->get();
```

A general use case example.
---------------------------

[](#a-general-use-case-example)

```
// routes/web.php
use Illuminate\Support\Facades\Route;
use Neelkanth\Laravel\Schedulable\Scopes\SchedulableScope;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/schedule/post', function () {
    $post = new App\Post();
    $post->title = "My scheduled post";
    $scheduleAt = Carbon\Carbon::now()->addDays(10);
    $post->schedule($scheduleAt);
    return $post; //The scheduled post's ID is 1
});

Route::get('/unschedule/post', function () {

    // To unschedule a post you have to fetch the scheduled post first.
    // But becuase the Schedulable trait is used in App\Post model it will not a fetch a post whose schedule_at column value is in future.

    $post = App\Post::find(1);  //This will return null for a scheduled post whose id is 1.

    //To retreive a scheduled post you can use any of the two methods given below.

    $post = App\Post::withScheduled()->find(1); //1. Using withScheduled() [Recommended]

    $post = App\Post::withoutGlobalScope(SchedulableScope::class)->find(1); //2. Using withoutGlobalScope()

    $post->unschedule();
});

```

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Neelkanth Kaushik](https://github.com/username)
- [All Contributors](../../contributors)

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

2030d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8d024795d1517d97c691382c2ff955cb3157ccab11222cbcb3b91d00bc2fe8c1?d=identicon)[Neelkanth Kaushik](/maintainers/Neelkanth%20Kaushik)

---

Top Contributors

[![neelkanthk](https://avatars.githubusercontent.com/u/16952465?v=4)](https://github.com/neelkanthk "neelkanthk (31 commits)")

---

Tags

eloquenteloquent-modelshacktoberfesthacktoberfest-acceptedhacktoberfest2024laravellaravel-frameworklaravel-packagelaravel-schedulephpphp7schedulable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/neelkanthk-laravel-schedulable/health.svg)

```
[![Health](https://phpackages.com/badges/neelkanthk-laravel-schedulable/health.svg)](https://phpackages.com/packages/neelkanthk-laravel-schedulable)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[abbasudo/laravel-purity

elegant way to add filter and sort in laravel

514330.5k1](/packages/abbasudo-laravel-purity)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
