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