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