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