Generate previous attributes when saving Eloquent models
https://twitter.com/SteveTheBauman/status/1524865758043553816. Credit to Steve Bauman.
FromThis package provides a trait that will generate previous attributes when saving any Eloquent model.
$model = EloquentModel::create(['name' => 'Awesome application']);
$model->update(['name' => 'New attribute']);
$model->getPrevious(); // ['name' => 'Awesome application']
$model->getPrevious('name'); // 'Awesome application'
Support us
We invest a lot of resources into creating best in class open source packages. You can support by donating to
- Paypal
- BCA 8330123584
I appreciate you if you connect with me on Twitter
Installation
You can install the package via composer:
composer require sawirricardo/laravel-previousable
Usage
Simply use the Sawirricardo\Previousable\HasPrevious
trait in your Eloquent Model.
Here's an example of how to implement the trait:
namespace App\Models;
use Sawirricardo\Previousable\HasPrevious;
use Illuminate\Database\Eloquent\Model;
class EloquentModel extends Model
{
use HasPrevious;
}
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.