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