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