middleware(function ($request, $next) { $this->form = DocumentForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('bixo.employee.modules'), 'employee', guard_url('employee')); return $next($request); }); } /** * Display a list of document. * * @return Response */ public function index(DocumentResourceRequest $request) { $request = $request->all(); $page = DocumentActions::run('paginate', $request); $data = new DocumentsCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('employee::document.names')) ->view('employee::document.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display document. * * @param Request $request * @param Model $document * * @return Response */ public function show(DocumentResourceRequest $request, Document $model) { $form = $this->form; $modules = $this->modules; $data = new DocumentResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('employee::document.name')) ->data(compact('data', 'form', 'modules')) ->view('employee::document.show') ->output(); } /** * Show the form for creating a new document. * * @param Request $request * * @return Response */ public function create(DocumentResourceRequest $request, Document $model) { $form = $this->form; $modules = $this->modules; $data = new DocumentResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('employee::document.name')) ->view('employee::document.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new document. * * @param Request $request * * @return Response */ public function store(DocumentResourceRequest $request, Document $model) { try { $request = $request->all(); $model = DocumentAction::run('store', $model, $request); $data = new DocumentResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('employee::document.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('employee/document/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/employee/document')) ->redirect(); } } /** * Show document for editing. * * @param Request $request * @param Model $document * * @return Response */ public function edit(DocumentResourceRequest $request, Document $model) { $form = $this->form; $modules = $this->modules; $data = new DocumentResource($model); // return view('employee::document.edit', compact('data', 'form', 'modules')); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('employee::document.name')) ->view('employee::document.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the document. * * @param Request $request * @param Model $document * * @return Response */ public function update(DocumentResourceRequest $request, Document $model) { try { $request = $request->all(); $model = DocumentAction::run('update', $model, $request); $data = new DocumentResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('employee::document.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('employee/document/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('employee/document/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the document. * * @param Model $document * * @return Response */ public function destroy(DocumentResourceRequest $request, Document $model) { try { $request = $request->all(); $model = DocumentAction::run('destroy', $model, $request); $data = new DocumentResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('employee::document.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('employee/document/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('employee/document/' . $model->getRouteKey())) ->redirect(); } } }