jeudi 25 juin 2020

Why Observer's Saved method not working for while update the record in laravel 5.3

I have project in laravel 5.3 and i am using Observer for activity log of user, for that i have created one obeserver with saved() and deleted() method.

The saved() method is working fine for new record, while update the record saved() is not getting call nor updated() method.

I also try with deleted() method, that is also not getting call, here below is my code, please help.


    public function __construct()
    {
        // echo "dsd"; die();
    }

    public function saved($user)
    {
        if ($user->wasRecentlyCreated == true) {
            // Data was just created
            $action = 'created';
        } else {
            // Data was updated
            $action = 'updated';
        }
        
        UserAction::create([
            'user_id'      => Auth::user()->id,
            'action'       => $action,
            'action_model' => $user->getTable(),
            'action_id'    => $user->id
        ]);
    }

    public function deleting($user)
    {
        dd($user); 
    }
}



public static function boot() { 
        parent::boot(); 
        parent::observe(new \App\Observers\UserObserver); 
    }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3hWBcWS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire