PHPackages                             stfn/laravel-pending-updates - 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. stfn/laravel-pending-updates

ActiveLibrary[Database &amp; ORM](/categories/database)

stfn/laravel-pending-updates
============================

v1.0.0(3y ago)22341MITPHPPHP ^8.1

Since Jan 22Pushed 3y ago2 watchersCompare

[ Source](https://github.com/stfndamjanovic/laravel-pending-updates)[ Packagist](https://packagist.org/packages/stfn/laravel-pending-updates)[ Docs](https://github.com/stfndamjanovic/laravel-pending-updates)[ RSS](/packages/stfn-laravel-pending-updates/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (13)Versions (5)Used By (0)

Postpone model updates or temporarily keep them updated for some time
=====================================================================

[](#postpone-model-updates-or-temporarily-keep-them-updated-for-some-time)

[![Latest Version on Packagist](https://camo.githubusercontent.com/757305512723f986c187737eb05bc5d6312918e876be5666bf174613a92ecf7e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7374666e2f6c61726176656c2d70656e64696e672d757064617465732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stfn/laravel-pending-updates)[![GitHub Tests Action Status](https://camo.githubusercontent.com/20ed48cfac9f92aa9c2d50201b48f6f33f715fb770a477e7c11e0a907639e8e3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7374666e64616d6a616e6f7669632f6c61726176656c2d70656e64696e672d757064617465732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/stfndamjanovic/laravel-pending-updates/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/d764944b6b6fbabb2c09147290885783ba547505038c4d5101799fb1095e8722/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7374666e64616d6a616e6f7669632f6c61726176656c2d70656e64696e672d757064617465732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/stfndamjanovic/laravel-pending-updates/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)

When updating an Eloquent model, by using this package, you can postpone updating process for some time.

```
$news = News::find(1);

$news->postpone()
    ->startFrom('2023-01-01 00:00:00')
    ->keepForHours(24)
    ->update(['is_active' => true]);
```

The model itself will not be updated in this case. The package will just schedule an update for you. So this news will be active only on 1st January for the whole day and after that, the package will revert the news to its previous state.

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

[](#installation)

You can install the package via composer:

```
composer require stfn/laravel-pending-updates
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="pending-updates-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="pending-updates-config"
```

This is the contents of the published config file:

```
return [
    // Maximum postpone in days.
    'max_postpone_days' => 10,

    // The model uses to store pending updates.
    'model' => \Stfn\PendingUpdates\Models\PendingUpdate::class,
];
```

When running the console command `pending-updates:check` all pending updates will be checked and if there is a need to revert some update to original table, this command will do that for you.

That command needs to be scheduled in the Laravel console kernel.

```
// app/Console/Kernel.php
use Stfn\PendingUpdates\Commands\CheckPendingUpdates;

protected function schedule(Schedule $schedule)
{
   $schedule->command(CheckPendingUpdates::class)->everyMinute();
}
```

Usage
-----

[](#usage)

You should add the HasPendingUpdates trait to all models which need to have a pending update option.

```
use Illuminate\Database\Eloquent\Model;
use Stfn\PendingUpdates\Models\Concerns\HasPendingUpdates;

class Ticket extends Model
{
    use HasPendingUpdates;
}
```

With this in place, you will be able to postpone update of this model.

### Using keep for

[](#using-keep-for)

By using keep for, update will be performed at the moment, but package will revert changes after specific number of minutes, hours or days.

```
$ticket = Ticket::find(1);

// Update ticket price to 200 and keep it updated for 60 minutes.
$ticket->postpone()
    ->keepForMinutes(60)
    ->update(['price' => 200]);

// Update ticket price to 200 and keep it updated for 12 hours.
$ticket->postpone()
    ->keepForHours(12)
    ->update(['price' => 200]);

// Update ticket price to 200 and keep it updated for 3 days.
$ticket->postpone()
    ->keepForDays(3)
    ->update(['price' => 200]);
```

### Using delay for

[](#using-delay-for)

By using delay for, update will be performed later, after specific number of minutes, hours or days.

```
$ticket = Ticket::find(1);

// Update ticket price to 200 after 60 minutes from now and keep it like that for unlimited time.
$ticket->postpone()
    ->delayForMinutes(60)
    ->update(['price' => 200]);

// Update ticket price to 200 after 12 hours from now and keep it like that for unlimited time.
$ticket->postpone()
    ->delayForHours(12)
    ->update(['price' => 200]);

// Update ticket price to 200 after 3 days from now and keep it like that for unlimited time.
$ticket->postpone()
    ->delayForDays(3)
    ->update(['price' => 200]);
```

### Using timestamps

[](#using-timestamps)

You can also use timestamps to specify exact time when you want to update some model.

```
$product = Product::find(1);

// Update product to be unavailable from 1st January.
$product->postpone()
    ->startFrom("2023-01-01 00:00:00")
    ->update(['is_available' => false]);

// Update product to be unavailable until 4th January.
$product->postpone()
    ->revertAt("2023-04-01 00:00:00")
    ->update(['is_available' => false]);

// Update product to be unavailable from 1st January to 4th January.
$product->postpone()
    ->startFrom("2023-01-01 00:00:00")
    ->revertAt("2023-04-01 00:00:00")
    ->update(['is_available' => false]);
```

### Using combination

[](#using-combination)

A combination of specific minutes, hours, or days with timestamps is also possible.

```
$product = Product::find(1);

// Update product to be unavailable from 1st January and keep that state for 1 day.
$product->postpone()
    ->startFrom("2023-01-01 00:00:00")
    ->keepForDays(1)
    ->update(['is_available' => false]);

// Update product to became unavailable after 60 minutes from now and keep that state until 4th January.
$product->postpone()
    ->delayForMinutes(60)
    ->revertAt("2023-04-01 00:00:00")
    ->update(['price' => 200]);
```

### Using methods on the model

[](#using-methods-on-the-model)

By default, all fillable attributes are allowed to be postponed, but you can change that by overriding `allowedPendingAttributes` method.

```
use Illuminate\Database\Eloquent\Model;
use Stfn\PendingUpdates\Models\Concerns\HasPendingUpdates;

class Ticket extends Model
{
    use HasPendingUpdates;

    public function allowedPendingAttributes()
    {
        return ['price'];
    }
}
```

Keep in mind that those fields also need to be fillable.

Sometimes scheduled update may fail, for various reasons. By default, the package will send that exception to your configured external report service like Sentry, Flare, or Bugsnag and after that, the record from the `pending_updates` table will be removed. If you want to change this behavior, you can override the `updateCannotBeApplied` method on the `PendingUpdateModel`.

```
use Illuminate\Database\Eloquent\Model;
use Stfn\PendingUpdates\Models\PendingUpdate;

class CustomPendingUpdate extends PendingUpdate
{
    public function updateCannotBeApplied($exception, $model)
    {
        // Your custom logic here
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Credits
-------

[](#credits)

- [Stefan Damjanovic](https://github.com/stfndamjanovic)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.4% 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 ~13 days

Total

4

Last Release

1172d ago

Major Versions

v0.0.3 → v1.0.02023-03-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab08845d8fb0e2eb1bc4a304ab3a0919ca2c2a0ae0198689d4744047c6e5c809?d=identicon)[stfndamjanovic](/maintainers/stfndamjanovic)

---

Top Contributors

[![stfndamjanovic](https://avatars.githubusercontent.com/u/22433990?v=4)](https://github.com/stfndamjanovic "stfndamjanovic (38 commits)")[![mkeremcansev](https://avatars.githubusercontent.com/u/76810832?v=4)](https://github.com/mkeremcansev "mkeremcansev (1 commits)")

---

Tags

eloquentlaravelschedulelaravelstfndamjanoviclaravel-pending-updates

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/stfn-laravel-pending-updates/health.svg)

```
[![Health](https://phpackages.com/badges/stfn-laravel-pending-updates/health.svg)](https://phpackages.com/packages/stfn-laravel-pending-updates)
```

###  Alternatives

[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[spatie/laravel-sql-commenter

Add comments to SQL queries made by Laravel

1931.4M1](/packages/spatie-laravel-sql-commenter)[spatie/laravel-deleted-models

Automatically copy deleted records to a separate table

409109.8k4](/packages/spatie-laravel-deleted-models)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

203330.1k2](/packages/wnx-laravel-backup-restore)

PHPackages © 2026

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