PHP code example of wamesk / laravel-api-response

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

    

wamesk / laravel-api-response example snippets


return ApiResponse::response(201);

try {
    // code
} catch (\Exception $exception) {
    return ApiResponse::exception($exception);
}


return ApiResponse::message('Hello')->response(201);

return ApiResponse::code('1.2')->message('Hello')->response(201);

return ApiResponse::code('1.2', 'user')->response(201); // return "message": "user.1.2" as in Response example

return ApiResponse::code('1.2')->response(201); // When not provided second parameter it will use default and return "message": "api.1.2"

return ApiResponse::data(['id' => 1, 'name' => 'Jhon Jhonson'])->code('1.2')->message('Hello')->response(201);

return ApiResponseDev::errors(['email' => 'Email is 

$users = User::paginate(10);

return ApiResponse::collection($users, UserResource::class)->code('1.2')->message('Hello')->response(201);