PHP code example of obiefy / api-response

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

    

obiefy / api-response example snippets


use API;

...

public function index()
{
    $users = User::latest()->take(5)->get();

    return API::response(200, 'Latest 5 Users', $users);
}

public function index()
{
    $users = User::latest()->take(5)->get();

    return api()->response(200, 'Latest 5 Users', $users);
}

use API;

...

public function index()
{
    $users = User::latest()->take(5)->get();

    return API::response(200, 'Latest 5 Users', $users);
}

public function index()
{
    $users = User::latest()->take(5)->get();
    $code = ['code' => 30566];
    $error = ['error' => 'ERROR-2019-09-14'];

    return api()->response(200, 'Latest 5 Users', $users, $code, $error);
}

public function index()
{
    $users = User::latest()->take(5)->get();

    return api(200, 'Latest 5 Users', $users);
}

return api()->ok();

$users = User::latest()->take(5)->get();

return api()->ok("User list", $users);

return api()->notFound();

return api()->validation('These fields are