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