PHP code example of anhzf / laravel-rest-api

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

    

anhzf / laravel-rest-api example snippets


  use Anhzf\LaravelRestAPI\APIResponse;
  
  // end of some controller
  return APIResponse::message('[your message here]')->send();

  use Anhzf\LaravelRestAPI\APIResponse;
  
  $myData = ['foo', 'bar', 'baz'];
  // end of some controller
  return APIResponse::data(compact('myData'))->send();

  use Anhzf\LaravelRestAPI\APIResponse;
  
  // end of some controller
  return APIResponse::statusCode(404)
        ->message('Didn\'t find matched user!')
        ->send();

  use Anhzf\LaravelRestAPI\APIResponse;
  
  // end of some controller
  return APIResponse::error()
      ->statusCode(422)
      ->message('email field is 

  use Anhzf\LaravelRestAPI;
  
  class APIResponse {
    public static sendMessage(string $message);
    public static sendData(array $data);
    public static sendStatusCode(int $statusCode, bool $success = true);
    public static sendError(string $message = null, int $statusCode = JsonResponse::HTTP_BAD_REQUEST);
  }

  use Anhzf\LaravelRestAPI\APIResponse;
  
  return APIResponse::message('Fetched users data from database')
      ->sendData(compact('userData'));
 
APIResponse::data(array $data)