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