Skip to content

Instantly share code, notes, and snippets.

@thiagomarini
Last active December 20, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomarini/229cd7d02aa50a7b269927d811f9fdcd to your computer and use it in GitHub Desktop.
Save thiagomarini/229cd7d02aa50a7b269927d811f9fdcd to your computer and use it in GitHub Desktop.
Service Usage in Controller Example
<?php
/**
* Requests a call from the sales team
*
* @method PUT
* @param Request $request
* @param int $userId
* @param RequestPhoneCall\Service $requestCall
*
* @return Response
*/
public function requestCall(Request $request, int $userId, RequestPhoneCall\Service $requestCall): Response
{
try {
$payload = $request->json()->all();
$responseData = $requestCall->execute(
new RequestPhoneCall\Request(['user_id' => $userId], $payload)
)->getData();
Log::info('Request call successful', [
'action' => __METHOD__,
'user_id' => $userId,
'phone' => $payload['phone'],
'description' => sprintf('Merchant: %s (%s) requested a call.', $responseData['user']['name'], $responseData['user']['id'])
]);
return $this->ok([
'onboarding' => $responseData['onboarding'],
]);
} catch (ValidationException | BusinessException $e) {
Log::error('Request call failed', [
'action' => __METHOD__,
'user_id' => $userId,
'error_message' => $e->getMessage()
]);
return $this->badRequest($e->getErrors());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment