Update LikeController

This commit is contained in:
Daniel Supernault 2019-05-12 22:32:56 -06:00
parent f033f84159
commit 7974ad39c9
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -20,14 +20,12 @@ class LikeController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [
'item' => 'required|integer', 'item' => 'required|integer|min:1',
]); ]);
$profile = Auth::user()->profile; $profile = Auth::user()->profile;
$status = Status::withCount('likes')->findOrFail($request->input('item')); $status = Status::withCount('likes')->findOrFail($request->input('item'));
Cache::forget('transform:status:'.$status->url());
$count = $status->likes_count; $count = $status->likes_count;
if ($status->likes()->whereProfileId($profile->id)->count() !== 0) { if ($status->likes()->whereProfileId($profile->id)->count() !== 0) {
@ -48,8 +46,6 @@ class LikeController extends Controller
->take(1000) ->take(1000)
->pluck('status_id'); ->pluck('status_id');
Cache::put('api:like-ids:user:'.$profile->id, $likes, now()->addMinutes(1440));
if ($request->ajax()) { if ($request->ajax()) {
$response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count]; $response = ['code' => 200, 'msg' => 'Like saved', 'count' => $count];
} else { } else {