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