PHP code example of raditzfarhan / laravel-api-response
1. Go to this page and download the library: Download raditzfarhan/laravel-api-response 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/ */
raditzfarhan / laravel-api-response example snippets
// Success response
// using service container
$response = app('ApiResponse')->success();
// using alias
$response = \ApiResponse::success();
// Failed response
$response = \ApiResponse::failed();
// Example #1
return ApiResponse::httpCode(201)->message('Created new record!')->data(['name' => 'Raditz Farhan', 'country' => 'MY'])->success();
// or can be shorten to
return ApiResponse::created(['name' => 'Raditz Farhan', 'country' => 'MY']);
// Example #2
return ApiResponse::httpCode(422)->message('Validation error!')->errors(['name' => ['Name field is