Laravel model event binding not called

I'm adding validation to a BaseModel class which all eloquent models will eventually extend in my application.

The base class resembles:

class BaseModel extends Eloquent {

private $errors;
private $validator;

public function __construct()
{
    $this->validator = new BaseValidator(get_class($this));
}

public static function boot()
{
    parent::boot();
    static::creating(function($model) {
         return false;
      });
    static::saving(function($model)
    {
        return false;
    });
}

a sample concrete that extends the base:

class News extends BaseModel {
protected $guarded = ['audience', 'deleted_at'];
protected $table = 'zbw_news';

//relations, scopes, etc
}

Whenever I create a new object through artisan tinker, the saving closure isn't being triggered (it returns true when it should return false ). However, I can bind a closure directly on the model's static (instead of late static binding) and it works as expected:

News::saving(function($model) { return false; });

Any ideas why the boot method isn't being called properly or what I'm doing wrong here?

链接地址: http://www.djcxy.com/p/83194.html

上一篇: 如何在laravel中使用查询生成器使用模型事件

下一篇: 未调用Laravel模型事件绑定