public function postComment(Request $request) { try { $session_token = $request->get('session_token'); $post_id = $request->get('post_id'); $comment_text = $request->get('comment_text'); $customer = SessionUtil::getCustomer($session_token); $post = Post::find($post_id); $new_comment = new Comment(); $new_comment->customer_id = $customer->id; $new_comment->comment_text = $comment_text; $new_comment->save(); $post->comments()->save($new_comment); $timeAgo = new TimeAgo(); $data = ['id' => $new_comment->id, 'comment_text' => $new_comment->comment_text, 'customer_name' => $new_comment->customer->display_name, 'time_ago' => $timeAgo->inWords($new_comment->created_at)]; return Response::json(['status' => 1, 'message' => 'Success', 'data' => $data]); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }
public function newPost(Request $request) { try { $session_token = $request->get('session_token'); $customer = SessionUtil::getCustomer($session_token); $description = $request->get('description'); $photo = $request->file('photo'); $inputs = []; if ($photo) { //Upload Image $uploaded_path = FileUpload::upload($photo); $inputs['photo'] = $uploaded_path; } $inputs['description'] = $description; $inputs['customer_id'] = $customer->id; Post::create($inputs); return Response::json(['status' => 1, 'message' => 'Success']); } catch (Exception $e) { return Response::json(['status' => 0, 'message' => $e->getMessage()]); } }