/** * Display a listing of user conversations. * * @return Response */ public function index($user_id) { $conversations_users = ConversationUser::where('user_id', $user_id)->lists('conversation_id'); $conversations = array(); if ($conversations_users) { $conversations = Conversation::whereIn('id', $conversations_users)->get(); } return Response::json(['success' => true, 'result' => $conversations]); }
public function retriveGroupMessage() { $input = Input::all(); $user = Auth::user(); $messages = DB::table('conversation_message')->where('conversation_id', $input['conversationID'])->orderBy('id', 'desc')->get(); //$scope.messages = $messages; $userid = $user->id; $userList = ConversationUser::where('conversation_id', '=', $input['conversationID'])->get(); $userNotificationStatus = GroupNotificationStatus::where('conversation_id', '=', $input['conversationID'])->where('user_id', '=', $user->id)->get(); $userListArray = array(); $j = 0; foreach ($userList as $key => $value) { # code... //echo($value->user_id); $userInfo = DB::select('select * from users where id = ?', array($value->user_id)); $userListArray[$j]['id'] = $userInfo[0]->id; $userListArray[$j]['full_name'] = $userInfo[0]->firstname . ' ' . $userInfo[0]->lastname; $j++; } $i = 0; $tmessages['user_list'] = json_encode($userListArray); $tmessages['status'] = false; if (isset($userNotificationStatus[0])) { if ($userNotificationStatus[0]->status == 1) { # code... $tmessages['status'] = true; } } foreach ($messages as $message) { $user = DB::select('select * from users where id = ?', array($message->sender_id)); //print_r($user[0]->picture); $m = new \MomentPHP\MomentPHP($message->created_at); $momentFromVo = $m->fromNow(); $tmessages['mlist'][$i]['userid'] = $user[0]->id; $tmessages['mlist'][$i]['pic'] = base64_decode($user[0]->picture); $tmessages['mlist'][$i]['fname'] = $user[0]->firstname . " " . $user[0]->lastname; $tmessages['mlist'][$i]['message'] = $message->message; $tmessages['mlist'][$i]['created_at'] = $momentFromVo; $tmessages['mlist'][$i]['id'] = $message->id; $tmessages['mlist'][$i]['current_user'] = $userid; $i++; } return json_encode($tmessages); // }