2
I have a model Manifestation using SoftDeletingTrait to keep them inactive in the bank and in the ManifestationController I have the following method destroy():
$manifestation = Manifestation::findOrFail($id);
$manifestation->closedBy()->associate(Auth::user());
$manifestation->save(); // save para marcar o usuário que encerrou
$manifestation->delete();
And if soon after I use $manifestation->trashed(), he returns true, and so far everything is correct. However, I also have a method restore() in the controller, with the following:
$manifestation = Manifestation::withTrashed()->findOrFail($id);
$manifestation->closed_by_id = null;
$manifestation->save();
$manifestation->restore();
The problem is that if I use the $manifestation->trashed(), keep getting true as a result, even though the model is no longer inactive.
- This behavior is correct?
- Is there any way around and make the
trashed()returnfalseafter therestore()?
If I’m not mistaken there must be a flag, as well as the exists class Eloquent which may possibly be changed, but I couldn’t find it. I could instead use the trashed, check whether the value of deleted_at is null, but I want to avoid doing so, unless it’s the last option.
Remarks:
- It reappears in search results normally.
- I’m using
Laravel 4.2and I can’t change.
Vitor strange, because it does not happen this, if you used
restore()thetrashed()returnsfalseand used updelete()returnstrue, I just ran a test on an old code of mine. Theexistsis aboleanowhich returns true if there is the record in the database, in case your it will always exist as true, only false for new records.– novic