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