public function storeComment($id) { $thread = ForumThread::find($id); if ($thread == null) { Redirect::route('forum')->with('fail', "That thread does not exist."); } $validator = Validator::make(Input::all(), array('body' => 'required|min:5')); if ($validator->fails()) { return Redirect::route('forum-thread', $id)->withInput()->withErrors($validator)->with('fail', "Please fill in the form correctly."); } else { $comment = new ForumComment(); $comment->body = Input::get('body'); $comment->author_id = Auth::user()->id; $comment->thread_id = $id; $comment->category_id = $thread->category->id; $comment->group_id = $thread->group->id; if ($comment->save()) { return Redirect::route('forum-thread', $id)->with('success', "The comment was saved."); } else { return Redirect::route('forum-thread', $id)->with('fail', "An error occured wile saving."); } } }
public function storeComment($id) { $thread = ForumThread::find($id); if ($thread == null) { # code... return Redirect::route('forum-thread', $id)->with('fail', "There is nothing to do with this"); } $validator = Validator::make(Input::all(), ['comment' => 'required|min:4|max:65000']); if ($validator->fails()) { # code... return Redirect::route('forum-thread', $id)->withInput()->withErrors($validator)->with('fail', "please fix these errors"); } else { $comment = new ForumComment(); $comment->body = Input::get('comment'); $comment->author_id = Auth::user()->id; $comment->thread_id = $id; $comment->category_id = $thread->category_id; $comment->group_id = $thread->group->id; if ($comment->save()) { # code... return Redirect::route('forum-thread', $id)->with('success', "The comment is saved"); } else { return Redirect::route('forum-thread', $id)->with('fail', "An error occured while saving"); } } }
public function storeThreadComment($id) { $thread = ForumThread::find($id); if ($thread == null) { Redirect::route('forum-get-new-comment')->with('fail', "You posted to an invalid thread."); } $validator = Validator::make(Input::all(), array('body' => 'required|min:3|max:65000')); if ($validator->fails()) { return Redirect::route('forum-get-new-comment', $id)->withInput()->withErrors($validator)->with('fail', "Your Input doesn't match the requirements!"); } else { $comment = new ForumComment(); $comment->body = Input::get('body'); $comment->thread_id = $id; $comment->category_id = $thread->category_id; $comment->group_id = $thread->group_id; $comment->author_id = Auth::user()->id; if ($comment->save()) { return Redirect::route('forum-thread', $thread->id)->with('success', "Your comment has been added."); } else { return Redirect::route('forum-get-new-comment', $id)->with('fail', "An error occured while adding your comment")->withInput(); } } }
public function deleteThread($id) { $thread = ForumThread::find($id); if ($thread == null) { return Redirect::route('forum-home')->with('fail', "That thread doesn't exist."); } $category_id = $thread->category_id; $comments = $thread->comments; if ($comments->count() > 0) { if ($comments->delete() && $thread->delete()) { return Redirect::route('forum-category', $category_id)->with('success', "The thread was deleted."); } else { return Redirect::route('forum-category', $category_id)->with('fail', "An error occured while deleting the thread."); } } else { if ($thread->delete()) { return Redirect::route('forum-category', $category_id)->with('success', "The thread was deleted."); } else { return Redirect::route('forum-category', $category_id)->with('fail', "An error occured while deleting the thread."); } } }