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