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