/** * Store a newly created resource in storage. * * @return Response */ public function create(CreateAccountRequest $request, Guard $auth, AccountRepository $account_respository, PaymentAddressRepository $payment_address_repository, APIControllerHelper $helper) { $user = $auth->getUser(); if (!$user) { throw new Exception("User not found", 1); } // get the monitored address and that it is owned by the user $attributes = $request->only(array_keys($request->rules())); $payment_address = $helper->requireResourceOwnedByUser($attributes['addressId'], $user, $payment_address_repository); // create the account $create_vars = $attributes; $uuid = Uuid::uuid4()->toString(); $create_vars['uuid'] = $uuid; unset($create_vars['addressId']); $this->dispatch(new CreateAccount($create_vars, $payment_address)); return $helper->transformResourceForOutput($account_respository->findByUuid($uuid)); }