public function destroy(Subreddit $subreddit, Moderator $moderator) { $mod = Moderator::where('subreddit_id', $subreddit->id)->where('user_id', $moderator->user_id)->first(); $mod->delete(); Session::flash('message', 'Moderator has been deleted.'); Session::flash('alert-class', 'alert-success'); return redirect('subreddit/' . $subreddit->id . '/moderators/create'); }
/** * Function to get the moderator List * @param $email * @return string */ public function getModerator($email) { $return = 'failure'; $user = new User(); $user = $user->getUser($email); if (strcmp($user, "failure") != 0) { $moderators = Moderator::where('id', $user->getUserID($email))->get(); if ($this->checkModerator($moderators)) { foreach ($moderators as $moderator) { $return = $moderator; } } else { $return = 'failure'; } } return $return; }
public function search(Post $post, Request $request) { $query = $request->input('search'); $subredditId = $request->input('subreddit_id'); $subreddit = Subreddit::with('posts.votes')->with('moderators.user')->where('id', $subredditId)->first(); $posts = $subreddit->posts()->where('title', 'LIKE', '%' . $query . '%')->get(); $isModerator = $subreddit->moderators()->where('user_id', Auth::id())->exists(); $modList = Moderator::where('subreddit_id', '=', $subredditId)->get(); return view('subreddit.search', compact('query', 'subreddit', 'posts', 'isModerator', 'modList')); }
/** * Function to approve the user as moderator * @param $emailID * @return string */ public function approveAsModerator($emailID) { $return = 'failure'; $user = $this->getUser($emailID); if (strcmp($user, "failure") != 0) { $user->isAppliedForModerator = 0; $user->isModerator = 1; $user->save(); $moderator = new Moderator(); $return = $moderator->addModerator($emailID); if (strcmp($return, 'failure') != 0) { //todo send a mail for user promotion too $return = 'success'; } } return $return; }