adamthehutt/eloquent-constructed-event

This package is abandoned and no longer maintained. No replacement package was suggested.

Eloquent model trait to add a 'constructed' event, which will fire immediately after object construction

v1.3.0 2020-09-24 02:49 UTC

This package is auto-updated.

Last update: 2022-01-10 20:30:27 UTC


README

Eloquent model trait to add a 'constructed' event, which will fire immediately after object construction

Install

composer require adamthehutt/eloquent-constructed-event

Use

Add the trait to an Eloquent model:

class MyModel extends Model
{
    use AdamTheHutt\EloquentConstructedEvent\HasConstructedEvent;
}

Do interesting things after model construction:

public static function boot()
{
    static::registerModelEvent("constructed", function (MyModel $model) {
        $model->generateUuid();
        $model->tellTheWorldIExist();
    });
}