PHP code example of asifcode / api-response

1. Go to this page and download the library: Download asifcode/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/ */

    

asifcode / api-response example snippets



use Asifcode\ApiResponse\ApiResponse;

//general api response
return ApiResponse::response(200)->message('Hello World')->data()->send();

//laravel collection pagination response
return ApiResponse::response(200)->message('Hello World')->data()->pagination();

//request errors response 

protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(
            ApiResponse::response(422)->errors($validator->messages())->success(false)->send()
        );
    }