repository = $subcategory; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Classifieds\Category\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(\Classifieds\Category\Repositories\Presenter\SubcategoryPresenter::class) ->$function(); } $subcategories = $this->repository->paginate(); return $this->response->setMetaTitle(trans('category::subcategory.names')) ->view('category::subcategory.index', true) ->data(compact('subcategories', 'view')) ->output(); } /** * Display subcategory. * * @param Request $request * @param Model $subcategory * * @return Response */ public function show(SubcategoryRequest $request, Subcategory $subcategory) { if ($subcategory->exists) { $view = 'category::subcategory.show'; } else { $view = 'category::subcategory.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('category::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->setMetaTitle(trans('app.new') . ' ' . trans('category::subcategory.name')) ->view('category::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('category::subcategory.name')])) ->code(204) ->status('success') ->url(guard_url('category/subcategory/' . $subcategory->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/category/subcategory')) ->redirect(); } } /** * Show subcategory for editing. * * @param Request $request * @param Model $subcategory * * @return Response */ public function edit(SubcategoryRequest $request, Subcategory $subcategory) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('category::subcategory.name')) ->view('category::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('category::subcategory.name')])) ->code(204) ->status('success') ->url(guard_url('category/subcategory/' . $subcategory->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('category/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('category::subcategory.name')])) ->code(202) ->status('success') ->url(guard_url('category/subcategory/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('category/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('category::subcategory.name')])) ->status("success") ->code(202) ->url(guard_url('category/subcategory')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/category/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('category::subcategory.name')])) ->status("success") ->code(202) ->url(guard_url('/category/subcategory')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/category/subcategory/')) ->redirect(); } } }