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