N
N
NubasLol2018-12-11 21:10:23
Laravel
NubasLol, 2018-12-11 21:10:23

Eloquent update event, how to understand what data has been updated?

In the observer, you need to know which fields have changed in the model after the update, how to implement this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2018-12-11
@JhaoDa

The model has methods isDirty/ isClean/ hasChanges/ wasChangedand a couple of similar ones. Feel free to study the framework code.

A
Anton, 2018-12-11
@Yadalay

Just as an example:

$item->save();
$changes = $item->getChanges();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question