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