FindController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\WxArticleInfoModel;
  4. use App\Services\Base\ErrorCode;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Validator;
  7. class FindController extends Controller
  8. {/**
  9. * @api {get} /api/find/index 发现
  10. * @apiDescription 发现
  11. * @apiGroup Find
  12. * @apiParam {string} appid appid
  13. * @apiParam {int} [page] 分页参数
  14. * @apiPermission none
  15. * @apiVersion 0.1.0
  16. * @apiSuccessExample {json} Success-Response:
  17. * HTTP/1.1 200 OK
  18. {
  19. "status": true,
  20. "status_code": 0,
  21. "message": "",
  22. "data": {
  23. "current_page": 1,
  24. "data": [
  25. {
  26. "id": 1,
  27. "title": "test",
  28. "pic": "/upload/article/20171013/91a15c6f30ad510db5165dad5ac1fff9.jpg",
  29. "info": "驱蚊器翁",
  30. "viewed": 0,
  31. "sort": 1,
  32. "created_at": "2017-10-13 03:34:02",
  33. "updated_at": "2017-10-13 03:34:02"
  34. },
  35. ],
  36. "first_page_url": "http://www.s1.com/api/find/index?page=1",
  37. "from": 1,
  38. "last_page": 1,
  39. "last_page_url": "http://www.s1.com/api/find/index?page=1",
  40. "next_page_url": null,
  41. "path": "http://www.s1.com/api/find/index",
  42. "per_page": 10,
  43. "prev_page_url": null,
  44. "to": 3,
  45. "total": 3
  46. }
  47. }
  48. * @apiErrorExample {json} Error-Response:
  49. * HTTP/1.1 400 Bad Request
  50. */
  51. public function index(Request $request)
  52. {
  53. $validator = Validator::make($request->all(),
  54. [
  55. 'appid' => 'required',
  56. ],
  57. [
  58. 'appid.required' => 'appid不存在',
  59. ]
  60. );
  61. if ($validator->fails()) {
  62. return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
  63. }
  64. $appid = $request->input('appid');
  65. $articles = WxArticleInfoModel::where('appid',$appid)->orderBy('sort')->paginate();
  66. return $this->api($articles);
  67. }
  68. }