PHP code example of corporateip / laravel-api-response

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

    

corporateip / laravel-api-response example snippets


function getUser($id){
    // Get the data we wish to return
    $user = User:find($id);
    
    // If the user does not exist we return an error
    if(!$user){
        return ApiResponseFactory::notFound("User does not exist");
    }
    
    // Return the data by using a ReponseFactory
    return ApiResponseFactory::success($user);
}