'Laravel OBSERVER update process

In SESSObServer

public function updated(SESS $sESS)
{
    log::info("data updated");
    if ($sESS->wasChanged('is_active')) {
        log::info("data updated");
    }
}

IN Observer, created(SESS $sESS) function run but update is not run. How can i solve problem ?

I changed my query. Now, this is run. I didn't use get. I used first()

 $sess = SESS::where('sess_id', request('id'))->first();
        $sess->save();


Solution 1:[1]

  1. Make sure your Observer is registered.
# app/Providers/EventServiceProvider.php
use App\Models\SESS;
use App\Observers\SESSObserver;

class EventServiceProvider extends ServiceProvider
{
    public function boot()
    {
        SESS::observe(SESSObServer::class);
    }
}
  1. Make sure you're using the correct classes. The logger's class is Log (capital L)
public function updated(SESS $sESS)
{
    Log::info("data updated");
    if ($sESS->wasChanged('is_active')) {
        Log::info("data updated");
    }
}

Alternatively, I think you can still use info().

public function updated(SESS $sESS)
{
    info("data updated");
    if ($sESS->wasChanged('is_active')) {
        info("data updated");
    }
}
  1. If you're using apache, make sure the apache user can write to the log file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 IGP