repository = $search_log; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\B2buy\SearchLog\Repositories\Criteria\SearchLogResourceCriteria::class); } /** * Display a list of search_log. * * @return Response */ public function index(SearchLogRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\B2buy\SearchLog\Repositories\Presenter\SearchLogPresenter::class) ->$function(); } $search_logs = $this->repository->paginate(); return $this->response->setMetaTitle(trans('search_log::search_log.names')) ->view('search_log::search_log.index', true) ->data(compact('search_logs', 'view')) ->output(); } /** * Display search_log. * * @param Request $request * @param Model $search_log * * @return Response */ public function show(SearchLogRequest $request, SearchLog $search_log) { if ($search_log->exists) { $view = 'search_log::search_log.show'; } else { $view = 'search_log::search_log.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('search_log::search_log.name')) ->data(compact('search_log')) ->view($view, true) ->output(); } /** * Show the form for creating a new search_log. * * @param Request $request * * @return Response */ public function create(SearchLogRequest $request) { $search_log = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('search_log::search_log.name')) ->view('search_log::search_log.create', true) ->data(compact('search_log')) ->output(); } /** * Create new search_log. * * @param Request $request * * @return Response */ public function store(SearchLogRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $search_log = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('search_log::search_log.name')])) ->code(204) ->status('success') ->url(guard_url('search_log/search_log/' . $search_log->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/search_log/search_log')) ->redirect(); } } /** * Show search_log for editing. * * @param Request $request * @param Model $search_log * * @return Response */ public function edit(SearchLogRequest $request, SearchLog $search_log) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('search_log::search_log.name')) ->view('search_log::search_log.edit', true) ->data(compact('search_log')) ->output(); } /** * Update the search_log. * * @param Request $request * @param Model $search_log * * @return Response */ public function update(SearchLogRequest $request, SearchLog $search_log) { try { $attributes = $request->all(); $search_log->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('search_log::search_log.name')])) ->code(204) ->status('success') ->url(guard_url('search_log/search_log/' . $search_log->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('search_log/search_log/' . $search_log->getRouteKey())) ->redirect(); } } /** * Remove the search_log. * * @param Model $search_log * * @return Response */ public function destroy(SearchLogRequest $request, SearchLog $search_log) { try { $search_log->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('search_log::search_log.name')])) ->code(202) ->status('success') ->url(guard_url('search_log/search_log/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('search_log/search_log/' . $search_log->getRouteKey())) ->redirect(); } } /** * Remove multiple search_log. * * @param Model $search_log * * @return Response */ public function delete(SearchLogRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('search_log::search_log.name')])) ->status("success") ->code(202) ->url(guard_url('search_log/search_log')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/search_log/search_log')) ->redirect(); } } /** * Restore deleted search_logs. * * @param Model $search_log * * @return Response */ public function restore(SearchLogRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('search_log::search_log.name')])) ->status("success") ->code(202) ->url(guard_url('/search_log/search_log')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/search_log/search_log/')) ->redirect(); } } }