Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel updating eloquent event: getting the data

I have been reading about eloquent events. There is an event for every interaction with a Model: creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored.

I want to know the data from a Model when it has been updated and the data it has before. Is it possible? Because the documentation havent so much info about how to use these events.

like image 745
Alan Avatar asked Oct 11 '16 18:10

Alan


1 Answers

You're looking for getDirty() and getOriginal() methods.

User::updating(function ($user) {
    $dirty = $user->getDirty();
    $original = $user->getOriginal();
});
like image 169
Alexey Mezenin Avatar answered Nov 14 '22 23:11

Alexey Mezenin