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