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