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