Laravel Eloquent event inheritance

eloquent, inheritance, laravel, subclass

Solution

You can use late static binding in the parent's static `boot` method that laravel automatically calls:

class Content extends Eloquent
{

    public static function boot()
    {
        parent::boot();

        static::saving(function ($model) {
            // do something
        });
    }

}

Problem

When I do this: ``` class Content extends Eloquent { } Content::saving(function($content) { // do something }); class Article extends Content { } ``` The 'do something' event doesn't fire when saving an Article. Is there any way that Article can inherit this event binding?

Original source