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