5 years ago

Model events and Observers in Laravel 5.0

Posted 5 years ago by Andreyco

Hello folks. I am trying to hook into model events which work fine using model's boot method. I decided to extract desired functionality out of model to its dedicated observer.

The observer is registered in AppServiceProvider.php
Despite the fact Observer is initiated (it's constructor is called, indeed), observer's methods are never called.

public function register()

    // This service provider is a convenient place to register your services
    // in the IoC container. If you wish, you may make additional methods
    // or service providers to keep the code more focused and granular.


If I register this service provider right after model class definition (in same file) or in routes file (just to test), it works.

// file: app/Test.php
<?php namespace App;

class Test extends \Illuminate\Database\Eloquent\Model {}


What am I missing? Is the AppServiceProvider wrong place to register Observers?

Thanks for your help.

Please sign in or create an account to participate in this conversation.