PHP code example of itsdamien / laravel-api-controller
1. Go to this page and download the library: Download itsdamien/laravel-api-controller 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/ */
itsdamien / laravel-api-controller example snippets
use ItsDamien\Api\ApiController;
class MyController extends Controller {
use ApiController;
public function index() {
return $this->respond(['status' => 'hello world']);
}
}
//200 response
$this->respond();
//201 response
$this->respondCreated();
//500 error
$this->respondServerError();
//422 error
$this->respondUnprocessable();
//General error
$this->respondWithError('message here');