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