/** * Converts a sessionlike to a userlike. * @param Like $like * @param $user_id */ private function convertSessionToUserLike(Like $like, $user_id) { // Checks if the like already exists for the logged in user // if it does we need to unlike the session like if (Like::where('session_like', false)->where('user_id', $user_id)->where('likeable_type', $like->likeable_type)->where('likeable_id', $like->likeable_id)->exists()) { $like->delete(); return; } $like->session_like = false; $like->user_id = $user_id; $like->save(); }
/** * Execute the console command. * * @return void */ public function fire() { $threshold = Carbon::now()->subMinutes($this->config['lifetime']); $likes = Like::where('created_at', '<=', $threshold); if ($this->config['clean_only_session_likes']) { $likes->where('session_like', true); } $count = $likes->count(); foreach ($likes->get() as $like) { $like->delete(); } $this->info("Removed " . $count . " outdated likes"); }
/** * Delete likes related to the current record */ public function removeLikes() { Like::where('likeable_type', $this->morphClass)->where('likeable_id', $this->id)->delete(); }