InformationController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace App\Http\Controllers\Admin\Info;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Info\InformationService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * Information
  8. */
  9. class InformationController extends Controller
  10. {
  11. /**
  12. * @var InformationService
  13. */
  14. private $informationService;
  15. /**
  16. * InformationController constructor.
  17. *
  18. * @param InformationService $informationService
  19. */
  20. public function __construct(InformationService $informationService)
  21. {
  22. parent::__construct();
  23. // $this->middleware('checkUserPermission');
  24. $this->informationService = $informationService;
  25. }
  26. /**
  27. * 列表
  28. * @param Request $request
  29. *
  30. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  31. * @throws \Prettus\Repository\Exceptions\RepositoryException
  32. */
  33. public function index(Request $request)
  34. {
  35. $informations = $this->informationService->handleList($request);
  36. return $this->response->success($informations);
  37. }
  38. /**
  39. * 新增
  40. * @param Request $request
  41. *
  42. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  43. * @throws \Prettus\Validator\Exceptions\ValidatorException
  44. */
  45. public function store(Request $request)
  46. {
  47. $data = $this->validateData($request, [
  48. 'type_id' => 'required|integer',
  49. 'title' => 'required',
  50. 'subtitle' => 'nullable|sometimes',
  51. 'synopsis' => 'required',
  52. 'content' => 'required',
  53. ], [
  54. 'type_id' => '类型',
  55. 'title' => '标题',
  56. 'subtitle' => '副标题',
  57. 'synopsis' => '简介',
  58. 'content' => '内容',
  59. ]);
  60. $information = $this->informationService->handleStore($data);
  61. return $this->response->created($information, '创建成功');
  62. }
  63. /**
  64. * 详情
  65. * @param Request $request
  66. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  67. */
  68. public function show(Request $request)
  69. {
  70. $this->validate($request, ['id' => 'required|integer']);
  71. $information = $this->informationService->handleProfile($request->get('id'));
  72. return $this->response->success($information);
  73. }
  74. /**
  75. * 更新
  76. * @param Request $request
  77. *
  78. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  79. * @throws \Prettus\Validator\Exceptions\ValidatorException
  80. */
  81. public function update(Request $request)
  82. {
  83. $data = $this->validateData($request, [
  84. 'id' => 'required|integer',
  85. 'type_id' => '',
  86. 'title' => '',
  87. 'subtitle' => '',
  88. 'synopsis' => '',
  89. 'content' => '',
  90. ], []);
  91. $information = $this->informationService->handleUpdate($data);
  92. return $this->response->success($information, '更新成功');
  93. }
  94. /**
  95. * 删除
  96. * @param Request $request
  97. */
  98. public function destroy(Request $request)
  99. {
  100. $this->validate($request, ['id' => 'required|integer']);
  101. $re = $this->informationService->handleDelete($request->get('id'));
  102. if ($re) {
  103. return $this->response->ok('删除成功');
  104. }
  105. return $this->response->fail('删除失败');
  106. }
  107. }