From 9f928ae570a2b4cc5de9791e6a2d58a2b279f0ab Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 18 Jun 2019 00:31:30 -0600 Subject: [PATCH] Update LikeController --- app/Http/Controllers/LikeController.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/LikeController.php b/app/Http/Controllers/LikeController.php index 2b87353d0..ef4ab26ee 100644 --- a/app/Http/Controllers/LikeController.php +++ b/app/Http/Controllers/LikeController.php @@ -32,20 +32,23 @@ class LikeController extends Controller $like = Like::whereProfileId($profile->id)->whereStatusId($status->id)->firstOrFail(); $like->forceDelete(); $count--; + if($count >= 0) { + $status->likes_count = $count; + $status->save(); + } } else { $like = new Like(); $like->profile_id = $profile->id; $like->status_id = $status->id; $like->save(); $count++; + if($count >= 0) { + $status->likes_count = $count; + $status->save(); + } LikePipeline::dispatch($like); } - $likes = Like::whereProfileId($profile->id) - ->orderBy('id', 'desc') - ->take(1000) - ->pluck('status_id'); - if ($request->ajax()) { $response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count]; } else {