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