adamthehutt/eloquent-constructed-event

此包已被弃用且不再维护。未建议替代包。

Eloquent 模型特性,用于添加一个 'constructed' 事件,该事件将在对象构造后立即触发

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 模型特性,用于添加一个 'constructed' 事件,该事件将在对象构造后立即触发

安装

composer require adamthehutt/eloquent-constructed-event

使用

将特性添加到 Eloquent 模型

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

在模型构造后执行有趣的事情

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