Laravel 10 Observer attribute not working

35 views Asked by At

I have a ProductPrice Model which I register an observer attribute with ObservedBy on as follows

#[ObservedBy([ProductPriceObserver::class])]
class ProductPrice extends Model
{
    use HasFactory, HasUlids;

    protected $fillable = ['price', 'is_current', 'product_id'];

}

This doesn't fire the observer at all.

manually registering the observer in the boot method of EventServiceProvider works

    public function boot(): void
    {
        ProductPrice::observe(ProductPriceObserver::class);

    }

I am very keen on getting the above to work as it is much more neater reference here

0

There are 0 answers