我正在处理以下代码:
// BaseModel
abstract class BaseModel extends Eloquent {
public static function boot()
{
parent::boot();
static::saving(function($model)
{
echo 'Fired BaseModel';
});
}
}
// Project (extends BaseModel)
class Project extends BaseModel {
public static function boot()
{
parent::boot();
static::saving(function($model)
{
echo 'Fired Project';
});
}
}
将新/现有数据保存到项目模型时,这只会给我Fired BaseModel
。它根本不会触发项目模型上的保存事件。有没有办法克服这个限制?
答案 0 :(得分:1)
在调用父事件应解决之前先触发子事件
// Project (extends BaseModel)
class Project extends BaseModel {
public static function boot()
{
static::saving(function($model)
{
echo 'Fired Project';
});
parent::boot();
}
}