PHP code example of mohamed-ahmed / api-response
1. Go to this page and download the library: Download mohamed-ahmed/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/ */
mohamed-ahmed / api-response example snippets
sh
$this->setData(User::all());
$this->setData(User::paginate(10));
### v2.0.0
$res->data($items->items());
$res->paginate($items);
sh
try {
// logic
} catch (\Exception $e) {
$this->setException($e);
$this->setCode(500);
return $this->apiResponse();
}
### v2.0.0
$res->exception($e);
return $this->tojson();
sh
$this->setEc(1001); // Internal reference code
sh
return $this->apiResponse();
### v2.0.0
return $res->tojson();