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