/** * Reports a post * * @param int The id of the post */ public function report($id) { $forumPost = ForumPost::isAccessible()->findOrFail($id); $forumReport = ForumReport::whereCreatorId(user()->id)->wherePostId($id)->first(); if ($forumReport) { $this->alertFlash(trans('forums::already_reported')); } else { $forumReport = new ForumReport(['post_id' => $id]); $forumReport->creator_id = user()->id; $forumReport->save(); $this->alertFlash(trans('forums::reported')); } return Redirect::to('forums/threads/' . $forumPost->thread->id . '/' . $forumPost->thread->slug); }
/** * Deletes a thread * * @param int The id of the thread */ public function delete($id) { $forumPost = ForumPost::isAccessible()->findOrFail($id); $forumThread = ForumThread::findOrFail($id); $forum = $forumThread->forum; ForumPost::whereThreadId($forumThread->id)->delete(); /* * Updates the users posts counter */ $query = DB::table('forum_posts')->whereThreadId(DB::raw($forumThread->id))->groupBy('creator_id')->select('creator_id', DB::raw('COUNT(creator_id) AS count'))->toSql(); DB::table('users')->join(DB::raw('(' . $query . ') AS sq'), 'id', '=', 'creator_id')->update(['posts_count' => DB::raw('posts_count - count')]); $forumThread->delete(); $forum->refresh(); }