Don't allow re-liking or re-unliking

This commit is contained in:
Toby Zerner 2015-08-05 16:08:28 +09:30
parent d27f0403d8
commit 4a9f8e0f23

View File

@ -29,11 +29,13 @@ class PersistData
throw new PermissionDeniedException;
}
if ($liked) {
$currentlyLiked = $post->likes()->where('user_id', $actor->id)->exists();
if ($liked && ! $currentlyLiked) {
$post->likes()->attach($actor->id);
$post->raise(new PostWasLiked($post, $actor));
} else {
} elseif ($currentlyLiked) {
$post->likes()->detach($actor->id);
$post->raise(new PostWasUnliked($post, $actor));