1
I am using the Laravel 5 and would like to know if, after modifying an attribute of a model, it is possible to recover it.
For example:
$usuario = Usuario::where(['nome' => 'Wallace'])->first();
$usuario->nome = 'Guilherme';
In the above example, I modified the attribute nome
model. I wonder if you can recover the attribute nome
. Laravel "saves" the original value somewhere before saving the changes?
Of course I could do this by doing another consultation, but I don’t think this is the best way. So I won’t accept answers like.
I wonder if there is any way to recover the initial value of the "name" attribute of the model above, without making another query.
why don’t you take the next line of
$usuario = Usuario::wher...
this:$nomeOrig = $usuario->nome
. And then keep the original name returned saved. This is if I understood the question correctly– Miguel
It’s @Miguel, too, but if it was multiple camps, I’d have to do it one by one, right? In fact I know the answer, just really wanted to instigate to have more content from [tag:Laravel] on the site and see the creativity of the staff :D
– Wallace Maxters
I await your reply then... I am also curious. That is after making $user->save(); recover the data that was there before?
– Miguel
@Miguel no, I said "before". " After" I already know that there is no way, because the data are already from the table :D
– Wallace Maxters
Yes, of course, but it could be that I was in session implicitly without us knowing
– Miguel
Curious ok anyway. I get what you mean. But I don’t know
– Miguel
@Miguel actually has the getOriginal :D. I’ve said too much
– Wallace Maxters
I just saw yes. But that doesn’t hide the pass/token. I tested it here
– Miguel