/** * This is for JOINING comments_group table and comments table * to fetch the comment_group_name through comment_group_id * @return string * @throws Exception * @since 8th feb 2016 * @author Saurabh Kumar <*****@*****.**> */ public function getCommentsGrpNameFromCommentsGrpId() { try { $result = Comment::join('comments_groups', function ($join) { $join->on('comments.comment_group_id', '=', 'comments_groups.comment_group_id'); })->select()->get(); return $result; } catch (QueryException $e) { echo $e; } }
public function addCommentsAjaxHandler(Request $request) { $addGroup = $request->input('comment_group_name'); $userId = Session::get('ig_user')['id']; $this->validate($request, ['comment_group_name' => 'required|unique:comments_groups'], ['comment_group_name.unique' => 'This comment group has already created. Please choose some other name', 'comment_group_name.required' => 'Please Provide Some Group Name.']); $objComment = new Comment_group(); $input = array('comment_group_id' => '', 'comment_group_name' => $addGroup, 'added_by' => $userId); $result = $objComment->addNewCommentGroup($input); if ($result) { $comment_group_details = Comment_group::orderBy('comment_group_id', 'desc')->first(); $comment_group_id = $comment_group_details['comment_group_id']; } $comment = $request->input('comment1'); $this->validate($request, ['comment1' => 'required'], ['comment1.required' => 'Whats in your mind, Please enter something']); $objComment = new Comment(); $comment = explode(PHP_EOL, $comment); $cmnt1 = ''; foreach ($comment as $cmnt) { if (trim(preg_replace('/\\s+/', ' ', $cmnt)) != '') { $cmnt1 .= json_encode(trim(preg_replace('/\\s+/', ' ', $cmnt))) . ','; } } $cmnt2 = rtrim($cmnt1, ','); $cmnt2 = '[' . $cmnt2 . ']'; $input = array('comment_group_id' => $comment_group_id, 'comments' => $cmnt2, 'added_by' => $userId, 'comment_status' => '1'); $result = $objComment->addNewComment($input); if ($result) { return Redirect::back()->with(['status' => 'Success', 'msg' => 'Your comment has been successfully added.']); } else { return Redirect::back()->with(['status' => 'Error', 'msg' => 'Some Error Occurred, For checking errors, please again click on the add comments for group']); } }