1. Go to this page and download the library: Download isaackearl/artisan-api 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/ */
isaackearl / artisan-api example snippets
// For Laravel add this to config/app.php
IsaacKenEarl\LaravelApi\Providers\ArtisanApiServiceProvider::class
// For Lumen add this to bootstrap/app.php
$app->register(IsaacKenEarl\LaravelApi\Providers\ArtisanApiServiceProvider::class);
private $api;
public function __construct(ArtisanApiServiceInterface $apiService)
{
$this->api = $apiService;
}
public function index()
{
$users = User::all();
return $this->api->respondWithCollection($users, new UserTransformer());
}
// you can respondWithError or respondWithMessage and customize the status code
// and response code etc
return $this->api
->setStatus(401)
->setResponseCode(ResponseCodes::UNAUTHORIZED)
->respondWithError('Not logged in');
php
// do stuff like this
public function show() {
return Api::respondWithItem($user, new UserTransformer());
}
// or like this:
return Api::respondNotFound();