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