select(['id','image','cn_title','en_title','created_at']) ->orderBy('is_top','desc') ->orderBy('sort','asc') ->orderBy('created_at','desc') ->paginate(10); $cn_data = []; $en_data = []; foreach ($list as $value){ $cn['title'] = $value['cn_title']; $cn['id'] = $value['id']; $cn['image'] = $value['image']; $cn['created_at'] = date('Y年m月d日',strtotime($value['created_at'])); $en['title'] = $value['en_title']; $en['id'] = $value['id']; $en['image'] = $value['image']; $en['created_at'] = date('Y年m月d日',strtotime($value['created_at'])); $cn_data[] = $cn; $en_data[] = $en; } $cn_datas['items'] = $cn_data; $en_datas['items'] = $en_data; return $this->apiResponseSuccess('获取列表成功', [ 'cn' => $cn_datas, 'en' => $en_datas, 'total' => $list->total(), 'limit' => 10, ]); } /** * 获取新闻详情 * @return \Illuminate\Http\JsonResponse */ function getInfo(){ $id = CommonServer::creatServer()->filtrationStr('id');//获取需要查询的记录id if(empty($id)) return $this->apiResponseError('请选择正确新闻'); //查询数据 $info = News::where('id',$id)->first(); if(empty($info)) return $this->apiResponseError('新闻不存在'); $data= []; $data['cn']['title'] = $info['cn_title']; $data['cn']['content'] = $info['cn_content']; $data['en']['title'] = $info['en_title']; $data['en']['content'] = $info['en_content']; $data['created_at'] = date('Y.m.d',strtotime($info['created_at'])); return $this->apiResponseSuccess('获取成功', $data); } }