Installation
composer require irazasyed/docgen
Publish the config file (if needed):
php artisan vendor:publish --provider="Irazasyed\Docgen\DocgenServiceProvider"
Basic Usage
Facade class (e.g., YourPackageFacade)./**
* @param string $param Description of the parameter.
* @return mixed Description of the return value.
*/
public static function exampleMethod($param) { ... }
php artisan docgen:generate
resources/docs/ (configurable).First Use Case
Generate a Markdown file for your facade’s API to include in your package’s README.md or documentation.
Integrating with CI/CD Add the generation step to your CI pipeline (e.g., GitHub Actions):
- name: Generate Docs
run: php artisan docgen:generate
Commit the generated files to your repo (or store them in a separate branch).
Customizing Output Override the default template by publishing the views:
php artisan vendor:publish --tag="docgen-views"
Modify resources/views/docgen/markdown.blade.php to fit your branding.
Dynamic Documentation
Use the --force flag to regenerate docs on every push:
php artisan docgen:generate --force
Facade-Only Packages For packages without a facade, extend the generator to support service classes by:
DocgenCommand.generate() to parse non-facade classes.config('docgen.path') to dynamically set output paths per environment.config/docgen.php:
'facades' => [
'YourPackage\\Facades\\*',
],
README.md via:
<!-- AUTO-GENERATED-DOCS:START -->
@include 'docs/your-package.md'
<!-- AUTO-GENERATED-DOCS:END -->
Facade Discovery
config/docgen.php or auto-discovered via Facade::class.'facades' => [
'YourPackage\\Facades\\YourFacade',
],
PHPDoc Parsing
@throws, @template) may break parsing.DocgenServiceProvider::boot():
$this->app->singleton('docgen.parser', function () {
return new CustomParser();
});
Caching
--force is used.php artisan cache:clear && php artisan docgen:generate
Namespace Conflicts
@method tags:
/**
* @method static string yourMethodAlias(string $param)
*/
config/docgen.php:
'debug' => env('DOCGEN_DEBUG', false),
Illuminate\Support\Facades\Facade:
use Illuminate\Support\Facades\Facade;
class YourFacade extends Facade { ... }
Custom Templates
Override the default Markdown template by publishing views and extending DocgenServiceProvider:
public function boot()
{
$this->loadViewsFrom(__DIR__.'/views', 'docgen');
}
Pre/Post-Generation Hooks Add logic before/after generation in a service provider:
Docgen::generating(function () {
// Pre-generation logic
});
Docgen::generated(function ($output) {
// Post-generation logic (e.g., upload to S3)
});
Non-Facade Classes Extend the generator to support services/controllers by:
php artisan make:command CustomDocgenCommand
ReflectionClass and integrating with Docgen’s output logic.How can I help you explore Laravel packages today?