PHP code example of kolirt / laravel-api-response

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

    

kolirt / laravel-api-response example snippets


return api()
        ->error()
        ->setCode(400) // default code 400

        ->setDescription(['Description #1', 'Description #2'])
        // or
        ->setDescription('Description')
        
        ->setData(['Data #1', 'Data #2'])
        // or
        ->setData('Data')
        
        ->render();

[
    'ok' => false,
    'error_code' => 400,
    
    'description' => ['Description #1', 'Description #2'],
    // or
    'description' => 'Description',
    
    'result' => ['Data #1', 'Data #2'],
    // or
    'result' => 'Data',
]

return api()
        ->success()
        ->setCode(200) // default code 200

        ->setDescription(['Description #1', 'Description #2'])
        // or
        ->setDescription('Description #1')
        
        ->setData(['Data #1', 'Data #2'])
        // or
        ->setData('Data')
        
        ->render();

[
    'ok' => true,
    
    'description' => ['Description #1', 'Description #2'],
    // or
    'description' => 'Description',
    
    'result' => ['Data #1', 'Data #2'],
    // or
    'result' => 'Data',
]

return api()->error();

return api()->success();

return api()->setCode($code);

return api()->setDescription(['Description #1', 'Description #2']);
// or
return api()->setDescription('Description');

return api()->setErrors([
    'first_name' => 'Error message', 
    'last_name' => ['Error message 1', 'Error message 2']
]);

return api()->abort('Error message', 400);

return api()->cookie(cookie('token', 'asdsadsadas', 60 * 3));

return api()->setData(['Data #1', 'Data #2']);
// or
return api()->setData('Data');

return api()->render();