Installation:
composer require --dev easycorp/easy-doc-bundle
(Note: While this is a Symfony package, Laravel developers can use it via Symfony’s Console component or by integrating it into a custom command.)
Enable the Bundle (Laravel Adaptation):
AppKernel, create a custom Artisan command to trigger the documentation generation. Add this to app/Console/Commands/GenerateDoc.php:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use EasyCorp\Bundle\EasyDocBundle\Command\DocCommand;
class GenerateDoc extends Command
{
protected $signature = 'doc:generate';
protected $description = 'Generate application documentation';
public function handle()
{
$docCommand = new DocCommand();
$docCommand->run(new \Symfony\Component\Console\Input\ArrayInput([]), new \Symfony\Component\Console\Output\ConsoleOutput());
}
}
app/Console/Kernel.php:
protected $commands = [
\App\Console\Commands\GenerateDoc::class,
];
First Use Case:
Run the command to generate documentation in public/docs/ (or a custom path):
php artisan doc:generate
public/docs/index.html in a browser to view the generated documentation.Integrate with CI/CD:
main:
# .github/workflows/docs.yml
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: composer install --no-dev
- run: php artisan doc:generate
- uses: actions/upload-artifact@v3
with:
name: documentation
path: public/docs/
Customize Output Path:
easy_doc.yaml:
# config/easy_doc.yaml
output_dir: 'storage/app/docs'
Extend Documentation:
Panel classes. Example:
// app/EasyDoc/CustomPanel.php
namespace App\EasyDoc;
use EasyCorp\Bundle\EasyDocBundle\Panel\PanelInterface;
class CustomPanel implements PanelInterface
{
public function getName(): string
{
return 'Laravel Jobs';
}
public function getContent(): string
{
return $this->renderJobsList();
}
}
// app/Providers/EasyDocServiceProvider.php
public function register()
{
$this->app->extend('easy_doc.panels', function ($panels) {
$panels[] = new \App\EasyDoc\CustomPanel();
return $panels;
});
}
Generate Docs on Demand:
// routes/web.php
Route::get('/admin/docs', function () {
Artisan::call('doc:generate');
return redirect()->to('/docs/index.html');
});
Onboarding New Developers:
public/docs/index.html for a high-level overview of routes, services, and bundles.Debugging:
routes or a deprecated bundle in the bundles panel).Client Deliverables:
public/docs/ directory and include it in project handoffs for transparency.HttpKernel or DependencyInjection components if you need deeper integration (e.g., for dynamic panel content).// webpack.mix.js
mix.copy('public/docs', 'public/docs-built');
// Override EasyDocBundle's output handler
$this->app->bind('easy_doc.output_handler', function () {
return new \App\Services\S3OutputHandler();
});
Symfony Dependency:
Kernel and Console components. If you encounter issues, ensure compatibility by:
symfony/console and symfony/http-kernel as dev dependencies:
composer require --dev symfony/console symfony/http-kernel
Application class in your custom command if needed.Outdated Releases:
Performance:
// Cache the generated HTML for 1 hour
$content = Cache::remember('easy_doc_html', 3600, function () {
return $this->generateDocContent();
});
Template Overrides:
resources/views/vendor/easy_doc/
php artisan view:clear
Command Errors:
php artisan doc:generate --verbose
Input/Output handling if the command fails silently.Missing Panels:
easy_doc.panels service. Use Laravel’s bind() method (as shown above) to inject custom panels.Bundle Not Found:
EasyDocBundle is loaded in your AppServiceProvider or a dedicated service provider.AppKernel-style registration is adapted to Laravel’s autoloading.Laravel-Specific Panels:
routes panel to include Laravel’s route model binding or API resource docs.Version Control:
public/docs/ to your repository for consistency, but exclude it from CI/CD pipelines to avoid bloating artifacts. Use .gitignore:
public/docs/
!public/docs/.gitkeep
Dynamic Content:
public function getContent(): string
{
$jobs = \DB::table('jobs')->get();
return $this->twig->render('EasyDocBundle:Panel:jobs.html.twig', ['jobs' => $jobs]);
}
Localization:
vendor/easycorp/easy-doc-bundle/Resources/translations/) for multilingual docs.Security:
/docs route:
Route::middleware(['auth'])->get('/docs/{path}', function ($path) {
return file_get_contents(public_path("docs/{$path}"));
});
temporaryUrl() for S3).How can I help you explore Laravel packages today?