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