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