middleware('checkUserPermission'); $this->searchHistoryService = $searchHistoryService; } /** * 新增 * @must * @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, [ 'keyword' => 'required|string', 'type' => 'required', ], [ 'keyword' => '关键字', 'type' => '类型', ]); $data['guard'] = 'admins'; $data['user_id'] = login_admin_id(); $searchHistory = $this->searchHistoryService->handleStore($data); return $this->response->created($searchHistory, '创建成功'); } /** * 搜索历史 * @must * @param Request $request * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource * @throws \Illuminate\Validation\ValidationException */ public function history(Request $request) { $data = $this->validateData($request, [ 'type' => 'required', ], [ 'type' => '类型', ]); $lists = $this->searchHistoryService->handleHistory($data['type']); return $this->response->success($lists); } /** * 删除 * @must * @param Request $request */ public function destroy(Request $request) { $this->validate($request, ['id' => 'required|integer']); $re = $this->searchHistoryService->handleDelete($request->get('id')); if ($re) { return $this->response->ok('删除成功'); } return $this->response->fail('删除失败'); } }