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