albaroody/staging

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

v0.1.2 2025-04-29 00:10 UTC

This package is auto-updated.

Last update: 2025-04-29 00:23:31 UTC


README

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

Laravel Staging

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:

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

You can publish the config file with:
```bash
php artisan vendor:publish --tag="staging-config"

Usage


## Installation

You can install the package via composer:

```bash
composer require Albaroody/staging

You can publish and run the migrations 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"

This is the contents of the published config file:

return [
];

Optionally, you can publish the views using

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

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

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.