christhompsontldr/laravel-docit
Laravel package that generates and serves simple project documentation pages inside your app. Organize docs in files, publish assets, and browse them via web routes. Useful for internal guides, onboarding notes, and lightweight API docs.
Installation
composer require christhompsontldr/laravel-docit
Publish the config and assets:
php artisan vendor:publish --provider="ChrisThompson\Docit\DocitServiceProvider" --tag="docit-config"
php artisan vendor:publish --provider="ChrisThompson\Docit\DocitServiceProvider" --tag="docit-assets"
Configuration
Edit config/docit.php to define:
source (Markdown/Blade directory, default: resources/docit)build (output directory, default: public/docs)theme (customize HydePHP theme paths)First Use Case
Create a Markdown file (resources/docit/guide.md) with frontmatter:
---
title: Getting Started
---
# Welcome to Docit!
Write your docs in **Markdown** or **Blade**.
Generate static site:
php artisan docit:build
Access at /docs/guide.html.
Markdown + Blade Hybrid
resources/views/docit/partials/nav.blade.php).@include('docit.partials.alert', ['type' => 'info', 'message' => 'Note:'])
Versioning
resources/docit/v1/, resources/docit/v2/).build config per version in docit.php:
'versions' => [
'v1' => ['source' => 'resources/docit/v1', 'build' => 'public/docs/v1'],
'v2' => ['source' => 'resources/docit/v2', 'build' => 'public/docs/v2'],
],
CI/CD Pipeline
deploy.php (Deployer):
task('build-docs', function () {
run('php artisan docit:build');
})->desc('Generate documentation');
- name: Build Docs
run: php artisan docit:build
Theming
vendor/hydephp/hydephp/resources/views to resources/views/docit.config/docit.php:
'theme' => [
'views' => 'resources/views/docit',
'assets' => 'resources/assets/docit',
],
Dynamic Content
resources/docit/api.blade.md):
@php
$routes = \Route::getRoutes()->getByName();
@endphp
## API Endpoints
@foreach($routes as $route)
- `{{ $route->uri }}` ({{ $route->methods()[0] }})
@endforeach
Frontmatter Parsing
# ❌ Fails
tags: ['api', 'auth',]
# ✅ Works
tags: ['api', 'auth']
Blade Caching
php artisan view:clear
Asset Paths
@asset() in Blade for correct public path resolution:
<link rel="stylesheet" href="{{ asset('docs/css/custom.css') }}">
Markdown Extensions
config/docit.php:
'markdown' => [
'extra' => ['tables', 'fenced_code'],
],
--verbose to diagnose issues:
php artisan docit:build --verbose
bootstrap/cache/docit.log for errors.Custom Processors
Extend DocitProcessor to add pre/post-processing:
// app/Providers/DocitServiceProvider.php
public function boot()
{
$this->app->extend('docit.processor', function ($processor) {
$processor->afterRender(function ($content, $file) {
return str_replace('{{ VERSION }}', '1.0.0', $content);
});
return $processor;
});
}
Hooks
Bind to docit.beforeBuild/docit.afterBuild events:
// app/Providers/EventServiceProvider.php
protected $listen = [
'ChrisThompson\Docit\Events\BeforeBuild' => [
\App\Listeners\BackupDocs::class,
],
];
Custom Commands Create a new Artisan command to extend functionality:
php artisan make:command DocitDeploy
// app/Console/Commands/DocitDeploy.php
public function handle()
{
$this->call('docit:build');
$this->deployToS3();
}
How can I help you explore Laravel packages today?