123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace App\Http\Controllers\Admin\Info;
- use App\Http\Controllers\Controller;
- use App\Services\Info\InformationService;
- use Illuminate\Http\Request;
- /**
- * Information
- */
- class InformationController extends Controller
- {
- /**
- * @var InformationService
- */
- private $informationService;
- /**
- * InformationController constructor.
- *
- * @param InformationService $informationService
- */
- public function __construct(InformationService $informationService)
- {
- parent::__construct();
- // $this->middleware('checkUserPermission');
- $this->informationService = $informationService;
- }
- /**
- * 列表
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function index(Request $request)
- {
- $informations = $this->informationService->handleList($request);
- return $this->response->success($informations);
- }
- /**
- * 新增
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function store(Request $request)
- {
- $data = $this->validateData($request, [
- 'type_id' => 'required|integer',
- 'title' => 'required',
- 'subtitle' => 'nullable|sometimes',
- 'synopsis' => 'required',
- 'content' => 'required',
- ], [
- 'type_id' => '类型',
- 'title' => '标题',
- 'subtitle' => '副标题',
- 'synopsis' => '简介',
- 'content' => '内容',
- ]);
- $information = $this->informationService->handleStore($data);
- return $this->response->created($information, '创建成功');
- }
- /**
- * 详情
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- */
- public function show(Request $request)
- {
- $this->validate($request, ['id' => 'required|integer']);
- $information = $this->informationService->handleProfile($request->get('id'));
- return $this->response->success($information);
- }
- /**
- * 更新
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function update(Request $request)
- {
- $data = $this->validateData($request, [
- 'id' => 'required|integer',
- 'type_id' => '',
- 'title' => '',
- 'subtitle' => '',
- 'synopsis' => '',
- 'content' => '',
- ], []);
- $information = $this->informationService->handleUpdate($data);
- return $this->response->success($information, '更新成功');
- }
- /**
- * 删除
- * @param Request $request
- */
- public function destroy(Request $request)
- {
- $this->validate($request, ['id' => 'required|integer']);
- $re = $this->informationService->handleDelete($request->get('id'));
- if ($re) {
- return $this->response->ok('删除成功');
- }
- return $this->response->fail('删除失败');
- }
- }
|