Reputation: 67525
I'm using ajax to update my model User
, the ajax part works fine since the data is updated successfully in the database, inside my controller action the update performed by :
$user->update($data);
The part that doesn't work:
I've used boot
s method updated
inside my model like :
class User extends BaseModel
{
...
public static function boot()
{
parent::boot();
self::updated(function($model){
Log::info("updated");
dd($model);
});
}
}
The event was never reached I'm not sure why.
Problem: I'm trying to perform an action after the model update but the event doesn't fire.
Upvotes: 5
Views: 2319
Reputation: 40690
Here's what the manual states with update()
When issuing a mass update via Eloquent, the saved and updated model events will not be fired for the updated models. This is because the models are never actually retrieved when issuing a mass update.
You need to use save
to trigger events. Something like:
$user->fill($data);
$user->save();
This of course is assuming that $user
is a model and not a query builder instance.
Upvotes: 7
Reputation: 63
You are accessing the function statically: instead try using
self::updated(function($model){
Log::info("updated");
dd($model);
});
Upvotes: 0