trogne's avatar

observer not hit

I have an observer, and it's not hit on update.

In "AppServerProvider.php" :

    public function register()
    {
        die('this is hit');
        Link::observe(LinkObserver::class);
    }

The "die" works here. So I comment this line.

But then I add this "die" in "LinkOberver.php" :

    public function __construct()
    {
        die('HIT');
    }

This "die" is not even hit. Why ?

In LinkController, I have this :

        if (!$link->exists) {
            $link->save();
            //$link->update([  //refactored , moved to model observer
            //    'code' => $link->getCode(),
            //]);
        }

Upon save, the observer created method is not hit.

0 likes
1 reply
trogne's avatar
trogne
OP
Best Answer
Level 3

WOW!!! I found how to solve this :

I needed to move "Link::observe" inside a "boot" method in "AppServiceProvider".

    public function boot()
    {
        Link::observe(LinkObserver::class);
    }

Initailly, there was only a "register" method stub in there.

Please or to participate in this conversation.