PHP code example of jeevanjoshi / laravel-api-response

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

    

jeevanjoshi / laravel-api-response example snippets


use ApiResponse;

// Success response (200)
return ApiResponse::success($data, 'Users fetched');

// Created response (201)
return ApiResponse::created($data, 'User created');

// Paginated response (200)
return ApiResponse::paginated($users);

// Error response (500)
return ApiResponse::error('Something went wrong');

// Not found response (404)
return ApiResponse::notFound('User not found');

// Unauthorized response (401)
return ApiResponse::unauthorized();

// Forbidden response (403)
return ApiResponse::forbidden();

// Validation error response (422)
return ApiResponse::validation($errors);

// No content response (200)
return ApiResponse::noContent();