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