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