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