Create API Documentation Effortlessly
PhpLightDoc automatically analyzes your Laravel code and generates clean, simple, and interactive documentation.
Why PhpLightDoc?
Simplicity and speed over complexity and cost.
The Swagger Problem
Tired of writing verbose YAML or endless annotations? Swagger is powerful but often requires significant manual effort and clutters your code.
PhpLightDoc
PhpLightDoc hits the sweet spot. It's a free, open-source package that generates documentation automatically, requiring only minimal and intuitive PHP 8 attributes or comments.
Paid Tools
Tools like Scramble offer great automation but come with a price tag. This can be a barrier for indie developers and small projects.
Quick Start
Get up and running in a couple of minutes.
1. Install via Composer
composer require wfgm5k2d/php-light-doc
2. Publish Config & Views
php artisan vendor:publish --provider='Wfgm5k2d\PhpLightDoc\Providers\PhpLightDocServiceProvider'
3. Configure your .env file
# Your path to the documentation file
PATH_TO_FILE_DOCUMENTATION='/your_full_path_to_file/api_documentation.json'
# Directories to scan (comma-separated)
PATH_TO_DIR_SCAN='app/Domain,app/Http/Controllers'
# Directories to exclude (comma-separated)
PATH_TO_DIR_EXCLUDE='app/Http/Controllers/Admin,CustomBackupController'
4. Generate Your Documentation
Run the command, and your documentation will be available at the /doc route.
php artisan doc:generate
Documentation
Use simple PHP 8 attributes or comments to enrich your documentation.
Controller Grouping
Structure your documentation by organizing controllers into logical groups.
Via Comment
// group Users
final class UserController extends Controller
Via Attribute (recommended)
#[DocGName('Users')]
final class UserController extends Controller
Advanced Grouping
To create a more complex hierarchy, you can combine controller groups into one large category. To do this, pass a second parameter to the DocGName attribute.
Via Attribute (recommended)
// This controller will go into the "User API" subgroup within the main "Users" group
#[DocGName('User API', 'Users')]
final class UserController extends Controller {}
// This controller will go into the "Auth" subgroup within the same main group
#[DocGName('Auth', 'Users')]
final class AuthController extends Controller {}
Route Names
Give your API endpoints human-readable names for easy identification.
Via Comment
// name Create a compensation request
public function createApplication(Request $request): JsonResponse
Via Attribute (recommended)
#[DocRName('Create a compensation request')]
public function createApplication(Request $request): JsonResponse
Middleware Requirements
Specify authorization requirements or other custom headers directly in the documentation.
Via Comment
// middleware-name Authentication required
// middleware-value Authorization: Bearer {token}
final class SecureController extends Controller
Via Attribute (recommended)
#[DocMiddleware('Authentication required', 'Authorization: Bearer {token}')]
final class SecureController extends Controller
Response Codes
The package automatically detects response codes from your code, but you can also specify them manually.
Via Comment
// response-codes 200 404 500
public function getUserData(Request $request): JsonResponse
Via Attribute (recommended)
#[DocResponseCodes([200, 404, 500])]
public function getUserData(Request $request): JsonResponse
Contribute
The library is under active development. If you have ideas for improvements, bug fixes, or new features, we welcome your pull requests!