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