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