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