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