/** * Reset user avatar * * @param User $user */ public function resetAvatar(User $user) { if ($user->avatar) { if (!starts_with($user->avatar, 'http')) { $this->imageUpload->removeAvatar($user); } $this->userRepo->update($user, ['avatar' => '']); } }
/** * Delete category by id * * @param $id * @return bool */ public function deleteById($id) { $category = $this->category->findById($id); if ($category) { if ($category->icon) { $this->image->removeIcon($category); } $this->category->delete($category); return true; } return false; }
/** * Delete post by its id * * @param $id * @return bool */ public function deleteById($id) { $post = $this->post->findById($id); if (!$post) { return false; } $this->user->update($post->user, ['posts' => $post->user->posts - 1]); $this->imageUploadService->remove($post->featured); if ($post->type == 'image' || $post->type == 'gif') { $this->imageUploadService->remove($post->thumbnail); $this->imageUploadService->remove($post->media); } $this->post->delete($post); event(new PostWasDeleted($post)); return true; }