albaroody/staging

Allow any Laravel model to be saved as a draft (staged) into a separate system without affecting real database tables.

v0.1.5 2025-05-07 09:06 UTC

This package is auto-updated.

Last update: 2025-05-12 03:30:37 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Laravel Staging allows you to stage (draft) Eloquent models and their nested relationships into a clean, separate system before committing them permanently to your main database.

  • Stage parent models like Patient, Post, Order, etc.
  • Stage related models like Sales, Items, Comments, etc.
  • Hydrate full Eloquent models from staged data (not just arrays)
  • Promote staged data to production tables cleanly
  • Keep your main database structure untouched — no intrusive columns added!

Perfect for multi-step forms, draft publishing systems, and modular deferred saving workflows.

Installation

You can install the package via Composer:

composer require albaroody/staging

You can publish and run the staging migration with

php artisan vendor:publish --tag="staging-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="staging-config"

Usage

  1. Add the Stagable trait to your model:
use Albaroody\\Staging\\Traits\\Stagable;

class Patient extends Model
{
    use Stagable;
}
  1. Stage a model:
$patient = new Patient([
    'name' => 'John Doe',
]);

$patient->stage();
  1. Load a staged model:
$stagedPatient = Patient::findStaged($stagingId);

// Now you can use it like a normal model
echo $stagedPatient->name;
  1. Promote a staged model to the database:
$realPatient = $stagedPatient->promoteFromStaging();

Enjoy easy staging without cluttering your main table with extra columns

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.