1. Go to this page and download the library: Download johnylemon/laravel-apidocs 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/ */
johnylemon / laravel-apidocs example snippets
namespace App\Apidocs\Endpoints;
use Johnylemon\Apidocs\Endpoints\Endpoint;
use Johnylemon\Apidocs\Facades\Param;
class SampleEndpoint extends Endpoint
{
public function describe(): void
{
$this->title('List users')
->desc('Returns paginated list of users');
}
}
$this->uri('/users');
$this->method('POST');
$this->group('some-group-slug');
$this->deprecated();
$this->title('Create user resource');
$this->description('This endpoint contains logic for creating user resources based on provided data');
namespace App\Apidocs\Endpoints;
use Johnylemon\Apidocs\Endpoints\Endpoint;
use Johnylemon\Apidocs\Facades\Param;
class SampleEndpoint extends Endpoint
{
public function describe(): void
{
$this->title('List users')
->desc('Returns paginated list of users')
->query([
Param::int('page')->example(1)->default(1)->optional()
])
}
}
use Johnylemon\Apidocs\Facades\Param;
$this->query([
// parameter name will be `page`
Param::int('page')->example(1)->default(1)->optional()
// same effect:
'page' => Param::int('page')->example(1)->default(1)->optional()
// same effect:
'page' => Param::type('int')->example(1)->default(1)->optional()
// this parameter will be named `page_number`
'page_number' => Param::int('page')->example(1)->default(1)->optional()
])
Param::type('int');
Param::name('username');
Param::description('Unique username');
Param::
Param::optional();
Param::possible([10, 100, 1000]);
Param::enum([10, 100, 1000]);
Param::default(42);
Param::example(42);
use Johnylemon\Apidocs\Facades\Param;
$this->query([
Param::string('slug'), // `slug` property, that should have `string` type
Param::int('id'), // id `property`, that should have `int` type
Param::array('roles'), // `roles` property, that should have `array` type
])
use App\Apidocs\Params\PageParam;
(...)
$this->query([
PageParam::class
]);
php artisan apidocs:param PageParam
namespace App\Apidocs\Params;
use Johnylemon\Apidocs\Params\Param;
class PageParam extends Param
{
public function __construct()
{
$this->name('page')->type('int')->default(1)->eg(42)->optional();
}
}
use Johnylemon\Apidocs\Facades\Apidocs;
Apidocs::defineGroup('users', 'Users', 'Manage users');
Apidocs::defineGroup('tickets', 'Tickets'); // Last parameter is optional
php artisan apidocs:install
php artisan apidocs:endpoint SampleEndpoint
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.