all(); $document = DocumentWorkflow::run($trasition, $document, $request); $data = new DocumentResource($document); return $this->response->message(trans('messages.success.updated', ['Module' => trans('employee::document.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('employee/document/' . $document->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('employee/document/' . $document->getRouteKey())) ->redirect(); } } /** * Get the document and user for the workflow. * * @param PublicRequest $request * @param string $document * @param string $user * * @return Response */ public function get(PublicRequest $request, $document, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $document = Document::findBySignedId($document); $transitions = $this->transitions($document, $user); $user = user(); Auth::logout(); return $this->response->setMetaTitle(trans('employee::document.name') . ' ' . trans('Approvals')) ->view('employee::public.document.workflow') ->layout('mobile') ->data(compact('document', 'user', 'transitions')) ->output(); } /** * Display the workflow form for the document. * * @param PublicRequest $request * @param string $document * @param string $user * * @return Response */ public function post(PublicRequest $request, $document, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $transition = $request->transition; $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $document = Document::findBySignedId($document); $user = user(); $document = DocumentWorkflow::run($transition, $document, $request->all()); Auth::logout(); return response()->json( [ 'status' => 'success', 'url' => $request->url(), ] ); } private function transitions($document, $user) { $transitions = []; foreach ($document->workflow()->transitions($document) as $key => $value) { $name = $value->getName(); $array['url'] = URL::temporarySignedRoute('litecms.document.workflow', now()->addMinutes(3), [ 'guard' => 'admin', 'transition' => $name, 'document' => $document->getSignedId(now()->addMinutes(3)), 'user' => $user->getSignedId(now()->addMinutes(3)), 'trans' => 'en', ] ); $array['name'] = $name; $array['key'] = $name; $array['form'] = $document->workflow()->form($value); $array['label'] = trans('employee::document.workflow.' . $name); $transitions[] = $array; } return $transitions; } }