public function get_comments_by_user(Request $request) { $user = json_decode($_COOKIE['user'], true); try { $comments = Comments::whereUser_id($user[0]['id'])->orderBy('id', 'DESC')->limit(20)->get(); foreach ($comments as $com) { $doc = Doctors::find($com->doctor_id); $img = Images::whereUser_id($doc->user_id)->first(); $main_ob['com_data'] = $com; $main_ob['doc_first_name'] = $doc->first_name; $main_ob['doc_last_name'] = $doc->last_name; $main_ob['doc_img'] = $img->image_path; $res[] = $main_ob; } } catch (Exception $e) { $this->LogError('AjaxController Get_Comments_By_User Function', $e); } return response()->json($res); }