Tuesday, March 21, 2017

Laravel - etrepat/Baum softDelete, How to perform a full restore?

I'm using Etrepat/Baum in Laravel 5.4 and I want to use soft delete. For the soft delete I don't have problem, I simply:

$node = Category:find($id); 
$node->delete();

And the above eliminate the node and all its children.

However, how can I perform a restore?

$node = Category::withTrashed()->find($id);
$node->restore();

The above only restores a single node, but doesn't restore the entire hierarchical tree.

I tried to use relationships, such as children(), it restores children, but doesn't restore beyond depth 1.

$node->children()->withTrashed()->restore();

The descendants() method does not work as I expect ...

$node->descendants()->withTrashed()->restore();

How can I perform a full restore?



via Eleazar Reséndez del Ángel

Advertisement