PHP code example of doliveira / laravel-api-response-builder
1. Go to this page and download the library: Download doliveira/laravel-api-response-builder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
doliveira / laravel-api-response-builder example snippets
use Doliveira\LaravelResponseBuilder\JsonResponse;
return JsonResponse::success($data, 'Operation successful.');
use Doliveira\LaravelResponseBuilder\JsonResponse;
return JsonResponse::error(400, 'Bad request.', $data);
use Doliveira\LaravelResponseBuilder\XmlResponse;
$response = new XmlResponse($statusCode, $message, $data);
return $response->build();
'logging_level' => 'info',
'detailed_errors' => false,
'log_responses' => true,
'log_requests' => true,
'log_response_time' => true,
'logging_level' => 'info',
bash
php artisan vendor:publish --provider="Doliveira\LaravelResponseBuilder\Providers\ResponseBuilderServiceProvider"
xml
<response>
<status>200</status>
<message>Operation successful.</message>
<data>
<id>1</id>
<name>Example</name>
</data>
</response>
xml
<response>
<status>400</status>
<message>Bad request.</message>
<data/>
</response>