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