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