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