コード例 #1
0
 /**
  * 搜索
  *
  * @param Request $request
  * @auther yangyifan <*****@*****.**>
  */
 public function getSearch(Request $request)
 {
     //接受参数
     $search = $request->get('search', '');
     $sort = $request->get('sort', 'id');
     $order = $request->get('order', 'asc');
     $limit = $request->get('limit', 0);
     $offset = $request->get('offset', config('config.page_limit'));
     //解析params
     parse_str($search);
     //组合查询条件
     $map = [];
     if (!empty($email)) {
         $map['article.email'] = ['like', '%' . $email . '%'];
     }
     if (!empty($mobile)) {
         $map['admin_info.mobile'] = ['like', '%' . $mobile . '%'];
     }
     if (!empty($role_name)) {
         $map['r.role_name'] = ['like', '%' . $role_name . '%'];
     }
     if (!empty($status)) {
         $map['admin_info.status'] = $status;
     }
     $data = ArticleModel::search($map, $sort, $order, $limit, $offset);
     echo json_encode(['total' => $data['count'], 'rows' => $data['data']]);
 }
コード例 #2
0
 public function showPicture($id)
 {
     $segments = explode('/', $id);
     $todos = ArticleModel::find($segments);
     if (count($todos) > 0) {
         $path = $todos->pluck('article_filepath');
         $filename = $todos->pluck('article_filename');
         ob_end_clean();
         return response()->download(public_path() . $path[0], $filename[0], ['Content-Type' => 'image/png']);
     } else {
         return ['message' => 'NOT FOUND', 'state' => 'article picture'];
     }
 }
コード例 #3
0
 /**
  * 添加文章
  *
  * @param Request $request
  * @auther yangyifan <*****@*****.**>
  */
 public function postAdd(ArticleRequest $request)
 {
     $data = $request->all();
     //写入当前用户到数据
     $data['admin_info_id'] = $request->get('admin_info_id', Session::get('admin_info.id'));
     //写入数据
     $affected_number = ArticleModel::create($data);
     return $affected_number->id > 0 ? $this->response(200, trans('response.add_success'), [], true, url('admin/article/index')) : $this->response(400, trans('response.add_error'), [], false);
 }