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