PHP code example of ftd-educacao / default-api-response

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

    

ftd-educacao / default-api-response example snippets


    'providers' => [
    ...
        /*
         * FTD Default API Response
         */
         FTD\DefaultApiResponse\DefaultApiResponseServiceProvider::class,
    ],

  public function index()
  {
      return response()->success(App\User::all());
  }

  public function show(User $user)
  {
      return response()->success($user);
  }

  public function index()
  {
      $users = App\User::paginate(2);
    return response()->paginate($users);
  }

  //User Custom Request
  public function rules()
  {
    return [
        'name'      => 'uired|string|max:255'
    ];
  }

  ...

  public function response(array $errors)
  {
    return response()->error($errors);
  }

  ...
  return response()->success($data, 201);

  ...
  return response()->paginate($data, 206);

  ...
  return response()->error($data, 401);


  public function myCustomMethod()
  {
    return response()->custom(
      $content = [
            "Name" => "Rodolfo",
            "Age"=>13
            ],
      $status = 200,
      $headers = ["X-USER-INFO" => TRUE],
      $headerContentType = 'application/json'
    );
  }

  public function store()
  {
    return response()->defaultStatusCode(400);
  }