PHP code example of cofa / laravel-api-docs

1. Go to this page and download the library: Download cofa/laravel-api-docs 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/ */

    

cofa / laravel-api-docs example snippets


'title'     => '{tenant} API',
'base_url'  => 'https://{tenant}.example.com',
'output'    => ['spec_file' => 'resources/views/vendor/api-docs/{tenant}/openapi.json'],
'history'   => ['path' => 'resources/views/vendor/api-docs/{tenant}/history.json'],
'tenancy'   => ['enabled' => true],

'tenancy' => [
    'enabled'  => true,
    'resolver' => fn () => auth()->user()?->company_id,
    // or, if you run `config:cache`, an invokable class:
    // 'resolver' => \App\Docs\CurrentTenant::class,
],

'serve' => ['domain' => '{account}.example.com'],

'cache' => ['enabled' => true, 'store' => 'file'],

/**
 * @group Users
 *
 * Endpoints for managing user accounts.
 */
class UserController
{
    /**
     * Create a user
     *
     * Creates the account and sends the welcome email.
     *
     * @authenticated
     * @header X-Tenant acme  The tenant the user belongs to.
     * @bodyParam name string source
     */
    public function store(StoreUserRequest $request) { /* … */ }
}

use Cofa\ApiDocs\Attributes\{ApiDoc, ApiGroup, ApiHeader, ApiParam, ApiResponse, Authenticated, HideFromDocs};

#[ApiGroup('Users', description: 'Endpoints for managing user accounts.')]
class UserController
{
    #[ApiDoc(summary: 'Create a user', description: 'Creates the account and sends the welcome email.')]
    #[Authenticated]
    #[ApiHeader(name: 'X-Tenant', value: 'acme', 

public function bodyParameters(): array
{
    return [
        'name' => ['description' => 'The full name of the user.', 'example' => 'Ada Lovelace'],
    ];
}
bash
php artisan vendor:publish --tag=api-docs-config