PHP code example of mindedge / laravel-api-doc

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

    

mindedge / laravel-api-doc example snippets


// PostController.php

/**
 * Create a new post
 * @param PostCreateRequest $request
 * @param int $page_id The page to create this post on
 */
public function create(PostCreateRequest $request, int $page_id)
{
    $post = Post::create([
        'page_id' => $page_id,
        'title' => 'My Sample Post',
        'body' => 'Hello world!',
    ]);

    return response($post, 201);
}


use Jrogaishio\LaravelApiDoc\Doc;

// The base api path (typically the version) to scan for routes
// Doc::generate() defaults to '1.0'
$baseApiPath = '1.0';
$document = Doc::generate($baseApiPath);

// toOpenApi defaults to OpenApi version 3.0.3 and an export type of yaml
echo $document->toOpenApi();


use Jrogaishio\LaravelApiDoc\Doc;

$document = Doc::generate('1.0');
print_r($document->toOpenApi(format: 'json'));


use Jrogaishio\LaravelApiDoc\Doc;

$document = Doc::generate('1.0');
print_r($document->toOpenApi(format: 'array'));


use Jrogaishio\LaravelApiDoc\Doc;
use Jrogaishio\LaravelApiDoc\Global\Document;

$baseDocument = new Document([
    'name' => 'My Awesome Api',
    'description' => 'The Awesome API Documentation',
    'license' => ['name' => '', 'url' => ''],
    'contact' => '[email protected]',
    'version' => '1.0'
]);
$document = Doc::generate(doc: $baseDocument);

echo $document->toOpenApi();