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