pmx

Cannot make eloquent observer fire for specific model

Posted 11 months ago by pmx

I've been pulling my hair out with this issue and I've finally given up and i'm asking for help here!

I have observers working perfectly on my Customer model but they just refuse to work on my Orders model.

It's not throwing any errors, there is nothing in the log file either. It's just not running the observer.

I've cleared the cache, dumped the autoload file, and banged my desk with my fist but to no avail!

Anyone know whats happening here? I'd really appreciate any advice!

Some Code:

AppServiceProvider.php

...
    public function boot()
    {
        Customer::observe(CustomerObserver::class);
        Order::observe(OrderObserver::class);
        User::observe(UserObserver::class);
        Schema::defaultStringLength(191);
        
    }
...

OrderObserver.php

<?php

namespace App\Observers;

use App\Order;
use \Cache;
use \Carbon\Carbon;

class OrderObserver
{

    public function saving(Order $order) {
        // $order->searchable_name = $order->FullName;
    }

    public function saved(Order $order) {
        Cache::forever('updates.orders',Carbon::now()->timestamp);
    }
    public function created(Order $order) {
        Cache::forever('updates.orders',Carbon::now()->timestamp);
        $order->user->notify( new \App\Notifications\EmployeeOrderCreated( $order ));
    }
    public function deleted() {
        Cache::forever('updates.orders',Carbon::now()->timestamp);
    }
}

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

Reply to

Use Markdown with GitHub-flavored code blocks.