laravel-pivot-softdeletes
laravel-pivot-softdeletes copied to clipboard
Re-Attaching does not undelete
Hi!
When I do the "normal" ->detach($post->id)
I get as expected the timestamp at the deleted_at
column.
But when I'd like to set the reassignment again by using ->attach()
like:
$user->managedPosts()->attach(
[
$post->id => [
'relationship_type' => $pivotFields['relationship_type'],
'role_id' => $pivotFields['role_id'],
],
]
);
unfortunately the value of deleted_at
is not changed to NULL
and actually the assignment is still deleted.
I saw in the documentation about $post->tags()->restore([$tag->id]);
and I tried:
$user->managedPosts()->restore(
[
$post->id => [
'relationship_type' => $pivotFields['relationship_type'],
'role_id' => $pivotFields['role_id'],
],
]
);
but with no success.
IMHO using the standard Laravel method ->attach()
should reactivate the assignment by removing the timestamp from deleted_at