From https://twitter.com/SteveTheBauman/status/1524865758043553816. Credit to Steve Bauman.
This 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'
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
You can install the package via composer:
composer require sawirricardo/laravel-previousable
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;
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.