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