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