421c/autodoc-laravel
AutoDoc for Laravel automatically generates clear, up-to-date documentation from your existing Laravel codebase. It inspects routes, controllers, requests, and models to keep API and project docs accurate with minimal manual effort.
composer require 421c/autodoc-laravel (dev-only is usually fine: --dev), then publish the config with the package's publish tag (check php artisan vendor:publish output; typically --tag=autodoc-config).config/autodoc.php. The laravel block controls how Laravel route metadata is translated into the OpenAPI document, including how can:<ability> middleware becomes OpenAPI security roles. The new v2.2.2 key lives here: laravel.abilities_as_security_roles (default true).php artisan list | grep autodoc to confirm the exact name, commonly autodoc:generate). Inspect the output file (JSON/YAML) rather than trusting the config alone./api guarded by auth:sanctum plus can:view-invoice. Generate the docs and verify:
securitySchemes entry exists for your auth guard, andcan:<ability> middleware appears as a security requirement only if you want abilities treated as roles.laravel.abilities_as_security_roles => false early and define security schemes explicitly. This is the main decision to make on day one, because it changes the shape of every secured operation in the generated document.laravel config rather than documenting the whole app. Generate separate specs for api, admin, and internal endpoints if they have different auth models.git diff of the output, and publish the artifact to your docs host. This keeps documentation drift visible in pull requests.abilities_as_security_roles left true, can:approve-refund becomes a role-like requirement named after the ability. This works well when your abilities are stable, human-readable, and align with how consumers reason about permissions.laravel.abilities_as_security_roles => false when your security model is scope- or role-based at the gateway, or when ability names are internal implementation details (can:update,App\Models\Invoice). Then declare security requirements via config/annotations and keep the generated auth scheme but not the ability roles.'abilities_as_security_roles' => env('AUTODOC_ABILITIES_AS_SECURITY_ROLES', true),
config/autodoc.php before v2.2.2, the new laravel.abilities_as_security_roles key will be absent. Diff the package's config against yours after upgrades; behavior falls back to the package default (true), so nothing breaks, but the option silently does nothing until merged.php artisan config:clear and php artisan route:clear after config or route changes. Stale cached routes are the most common cause of "my new endpoint isn't in the docs."can: middleware is detected. Authorization performed inside controllers ($this->authorize(...), Gate::authorize, policy calls, form requests) will not produce security roles. If your abilities are enforced in code rather than middleware, the generated security section will understate requirements — document those explicitly or move the check into middleware.can:update,invoice style middleware can yield role strings containing model class names or arguments. Prefer named abilities (e.g. update-invoice) if you keep abilities_as_security_roles enabled, otherwise disable it.abilities_as_security_roles => false and expose only the auth scheme plus consumer-facing scopes.env() handles "false"/"true" strings, but values like "0" or empty strings can surprise you. Prefer explicit booleans and confirm with php artisan config:show autodoc (or tinker) after setting the env var.How can I help you explore Laravel packages today?