code-lts/doctum
Doctum for Laravel: generate versioned API documentation for your PHP codebase with a clean, searchable HTML output. Supports configuration, theming, and multi-version docs, making it easy to publish and maintain docs for packages and applications.
Installation (PHP 8.1+ required):
composer require code-lts/doctum --dev
Add to require-dev in composer.json for project-specific docs.
Configuration: Publish the config file:
php artisan vendor:publish --provider="Doctum\DoctumServiceProvider"
Update .env and config/doctum.php to define:
source (e.g., app/, src/)output (e.g., docs/)title and theme (default: bootstrap or bootstrap-4)First Run:
php artisan doctum:generate
Outputs HTML docs to docs/ (or your configured path).
Quick Use Case: Generate docs for a single class:
php artisan doctum:generate --filter=App\Services\PaymentService
CI/CD Integration (PHP 8.1+ required):
post-test or build phase:
# .github/workflows/docs.yml
- name: Generate Docs
run: php artisan doctum:generate
composer.lock) to avoid redundant installs.Versioned Documentation:
--output flag to generate per-branch docs:
php artisan doctum:generate --output=docs/v1.2
docs/latest for convenience.Incremental Updates:
--only-changed (if supported in future versions).git diff to regenerate only modified classes:
git diff --name-only HEAD~1 | xargs -I{} php artisan doctum:generate --filter={}
Custom Themes:
Extend the default theme by copying vendor/doctum/themes/bootstrap to resources/views/vendor/doctum and override templates (e.g., class.blade.php).
Enhanced PHPDoc Support:
@category Tag: Group related classes:
/**
* @category Authentication
*/
class LoginController {}
API Annotations: Use PHPDoc blocks for richer metadata:
/**
* @method static \App\Models\User findByEmail(string $email)
* @throws \InvalidArgumentException
*/
class UserRepository {}
Excluding Files:
Configure in config/doctum.php:
'exclude' => [
'app/Exceptions/*',
'app/Providers/*',
],
Markdown Support:
Embed Markdown in PHPDoc @description tags:
/**
* @description
* # Payment Processing
* - Supports **Stripe** and PayPal.
* - [See our guide](https://example.com/guide).
*/
Dynamic Output: Generate docs programmatically in tests or migrations:
use Doctum\Doctum;
$doctum = new Doctum();
$doctum->generate();
PHP Version Requirement:
php -v
Namespace Conflicts:
Doctum as a class name, rename the config file to avoid collisions:
mv config/doctum.php config/doctum_config.php
app/Providers/DoctumServiceProvider accordingly.Circular References:
--filter to generate subsets:
php artisan doctum:generate --filter=App\Models\*
Theme Dependencies:
bootstrap CSS/JS. Include them in your docs/index.html:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
PHPDoc Parsing Quirks:
@param syntax).php -l or use phpDocumentor/phpdocumentor for validation.Dependency Conflicts:
composer update to resolve conflicts.File Permissions:
storage/ and docs/ are writable:
chmod -R 775 storage docs
Verbose Output:
Enable debug mode in .env:
DOCTUM_DEBUG=true
Or run with:
php artisan doctum:generate --verbose
Log Generation:
Check storage/logs/doctum.log for parsing errors.
Dry Run:
Use --dry-run (if available) to preview changes without writing files.
TypeHint Resolution:
(string|int) instead of \string|\int).Custom Parsers:
Extend Doctum\Parsers\ParserInterface to support custom PHPDoc tags or annotations.
Post-Processing:
Hook into doctum.generated event in EventServiceProvider:
protected $listen = [
'doctum.generated' => [
'App\Listeners\DeployDocsToS3',
],
];
CLI Aliases:
Add to composer.json:
"extra": {
"laravel": {
"aliases": {
"docs:generate": "doctum:generate"
}
}
}
Git Hooks:
Auto-generate docs on pre-commit (use sparingly):
php artisan doctum:generate --only-changed
git add docs/
Localization:
Override language files in resources/lang/ to customize doc text (e.g., "Properties" → "Attributes").
Version Navigation:
PHPStan Integration: Leverage PHPStan’s improved doc parsing for stricter validation:
vendor/bin/phpstan analyse --level=max src/
How can I help you explore Laravel packages today?