public function store(Requests\SubredditRequest $request, Moderator $moderator, Subreddit $subreddit) { $sub = Auth::user()->subreddit()->create($request->all()); $moderator = new Moderator(); $moderator->user_id = Auth::id(); $moderator->subreddit_id = $sub->id; $moderator->save(); return redirect('/'); }
public function store(Requests\ModeratorRequest $request, Subreddit $subreddit, User $user) { if (Gate::denies('update-sub', $subreddit)) { } elseif (Moderator::where('user_id', '=', Input::get('user_id'))->where('subreddit_id', '=', $subreddit->id)->count() > 0) { Session::flash('message_info', 'User is already a moderator of this subreddit.'); Session::flash('alert-class', 'alert-warning'); return redirect('subreddit/' . $subreddit->id . '/moderators/create'); } else { $moderator = new Moderator(); $moderator->user_id = Input::get('user_id'); $moderator->subreddit_id = $subreddit->id; $moderator->save(); } if ($moderator) { Session::flash('message', 'Moderator has been added.'); Session::flash('success-class', 'alert-success'); } return redirect('subreddit/' . $subreddit->id . '/moderators/create'); }