PHP code example of emyoutis / laravel-whitehouse-responder

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

    

emyoutis / laravel-whitehouse-responder example snippets


WhiteHouseResponderErrors::register(
     '40001',
     'Verbose, plain language description of the problem. Provide developers suggestions about how to solve their problems here',
     'This is a message that can be passed along to end-users, if needed.',
     'http://www.example.gov/developer/path/to/help/for/444444'
);

WhiteHouseResponderErrors::unregister('40001');

    WhiteHouseResponderResponse::clientError('40001');
    

    WhiteHouseResponderResponse::serverError('40001');
    

WhiteHouseResponderResponse::error('40001', 422);

WhiteHouseResponderErrors::register(
     '40001',
     'The class `:class` is undefined.',
     'An error has been occurred in while finding the :entity.',
     'http://www.example.gov/developer/path/to/help/for/444444'
);

return WhiteHouseResponderResponse::clientError(40001, [
     'class'  => 'Entities/User',
     'entity' => 'user',
])

WhiteHouseResponderErrors::disableExceptions();

$results  = [
     [
          'id'    => 1,
          'title' => 'First Item',
     ],
     [
          'id'    => 2,
          'title' => 'Second Item',
     ],
];
$metadata = ['page' => 1];
    
$response = WhiteHouseResponderResponse::success($results, $metadata);

WhiteHouseResponderErrors::register(
     '40001',
     'Verbose, plain language description of the problem. Provide developers suggestions about how to solve their problems here',
     'This is a message that can be passed along to end-users, if needed.',
     'http://www.example.gov/developer/path/to/help/for/444444'
);

WhiteHouseResponderErrors::registerFormatter(function ($key) {
    return snake_case($key);
});


return WhiteHouseResponderErrors::clientError(40001);