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