Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Tomi's avatar
Level 8

Laravel 5.7 Upgrade, Observer problem

Hi,

for some reason after upgrading to Laravel 5.7 grom 5.6 i cant register Observers like this anymore:

class Partner extends Model
{
    /**
     * disabled searchable trait, because there is no elastic search cluster available yet.
     */
    use Searchable;
    use ObservantTrait;

    public static function boot()
    {
        static::observe(new PartnerObserver());
        parent::boot();
    }

I get a Fatal Error saying that there is an Undefined Error:

   /www/my-project/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php

   protected function initializeTraits()
    {
        foreach (static::$traitInitializers[static::class] as $method) {
            $this->{$method}();
        }
    }
0 likes
3 replies
qiutuleng's avatar
Level 2

The parent::boot() method must be called on the first line of the method. please swap the positions of the two line codes.

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

        static::observe(new PartnerObserver());
    }
11 likes
Tomi's avatar
Level 8

@qiutuleng thats working fine, do you have any idea why did that work before and now of a sudden it isnt?

qiutuleng's avatar

@Tomi I think it is an initial trait error. Can you list the detailed error message?

Please or to participate in this conversation.