PHP code example of wadakatu / laravel-spectrum

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

    

wadakatu / laravel-spectrum example snippets


// ❌ Traditional approach: Annotations everywhere
/**
 * @OA\Post(
 *     path="/api/users",
 *     @OA\RequestBody(
 *         @OA\JsonContent(
 *             @OA\Property(property="name", type="string"),
 *             @OA\Property(property="email", type="string", format="email"),
 *             // ... 50 more lines of annotations
 *         )
 *     ),
 *     @OA\Response(response="200", description="Success")
 * )
 */
public function store(StoreUserRequest $request) { ... }
bash
# Install
composer cumentation
php artisan spectrum:generate

# View in browser (HTML, default: Swagger UI)
php artisan spectrum:generate --format=html
# Or choose a viewer
php artisan spectrum:generate --format=html --viewer=elements
# Open: storage/app/spectrum/openapi.html
bash
php artisan spectrum:mock
# Frontend team can develop without waiting for backend
bash
php artisan spectrum:export:postman    # Postman collection
php artisan spectrum:export:insomnia   # Insomnia workspace
php artisan spectrum:sdk typescript    # Type-safe SDK client
bash
php artisan spectrum:validate storage/app/spectrum/openapi.json
php artisan spectrum:validate --generate --strict
bash
php artisan spectrum:diff docs/openapi-v1.json docs/openapi-v2.json
php artisan spectrum:diff --against=last --format=json
php artisan spectrum:version-compare docs/openapi-v1.json docs/openapi-v2.json --migration-guide