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