Prompt file imported from waw3/rer-form (
.claude/commands/getdb/laravel.md). Fill in{{OUTPUT}}before use. Copyright stays with the author.
Laravel Database Documentation
Generate comprehensive database documentation using Laravel's schema introspection with Eloquent relationships and Mermaid diagrams.
Usage
Generate database documentation with Laravel's artisan command:
# Basic usage (saves to api/docs/database.md)
/getdb:laravel
# Custom output location
/getdb:laravel --output docs/db-structure.md
# Save to Claude's reference location
/getdb:laravel --output ../claude/database.md
Examples
# Example 1: Default documentation generation
/getdb:laravel
# Example 2: Custom documentation path
/getdb:laravel --output docs/database-v2.md
# Example 3: Generate for project documentation
/getdb:laravel --output ../docs/technical/database.md
# Example 4: Update Claude's database reference
/getdb:laravel --output ../.claude/database.md
Command Execution
cd api && php artisan claude:getdb --output="{{OUTPUT}}"
Parameters
Optional Parameters
--output [file_path]: Output file path relative to api/ directory (default: docs/database.md)
Environment Variables
- Laravel uses database configuration from
api/.env DB_CONNECTION: Database driver (mysql)DB_DATABASE: Database nameDB_USERNAME: Database userDB_PASSWORD: Database password
Features
- Eloquent Awareness: Includes model relationships and scopes
- Mermaid Diagrams: Visual entity relationship diagrams
- Comprehensive Metadata: Column types, defaults, nullable flags
- Index Documentation: All indexes with type and uniqueness
- Foreign Key Mapping: Complete FK relationships with cascade rules
- Model Integration: Can include model-specific documentation
- Migration History: References migration files
- Automatic Formatting: Clean markdown with TOC
Requirements/Dependencies
System Requirements
- PHP 8.1 or higher
- Laravel 10 or higher
- Composer dependencies installed
- Database connection configured
Installation Verification
# Check Laravel installation
cd api && php artisan --version
# Verify command exists
php artisan list | grep claude:getdb
# Test database connection
php artisan tinker --execute="DB::connection()->getPdo()"
Output
Generated Documentation Structure
-
Header Section
- Generation timestamp
- Total table count
- Database statistics
-
Table of Contents
- Alphabetical table listing
- Quick navigation links
-
Entity Relationship Diagram
- Mermaid ER diagram
- Visual foreign key relationships
-
Per-Table Documentation
- Column specifications (name, type, nullable, default, auto-increment)
- Index definitions (name, columns, type, unique, primary)
- Foreign key constraints (name, columns, references, cascade rules)
Sample Output
# Database Structure
Generated on: 2024-01-15 10:30:00
Total tables: 165
## Table of Contents
- [entities](#entities)
- [reports](#reports)
...
## Entity Relationships
\```mermaid
erDiagram
reports ||--o{ entities : has
entities ||--o{ payments : has
\```
## reports
### Columns
| Column | Type | Nullable | Default | Auto Increment | Comment |
|--------|------|----------|---------|----------------|---------|
| id | char(26) | NO | NULL | NO | ULID primary key |
| firm_id | char(26) | NO | NULL | NO | Foreign key to firms |
...
Advanced Usage
Integration with Documentation
# Generate and commit documentation
/getdb:laravel --output docs/database.md
git add api/docs/database.md
git commit -m "Update database documentation"
Comparison Workflow
# Before schema changes
/getdb:laravel --output docs/db-before.md
# Make migrations
php artisan migrate
# After schema changes
/getdb:laravel --output docs/db-after.md
# Compare
diff api/docs/db-before.md api/docs/db-after.md
Notes
- Generation time: 10-30 seconds depending on table count
- Includes Laravel-specific metadata not available via raw SQL
- Respects Laravel's database abstraction layer
- Can include soft delete timestamps
- Mermaid diagrams require markdown viewer support
- File is saved relative to api/ directory
Troubleshooting
Common Issues
Issue 1: Command not found
- Solution: Ensure command is registered in Laravel
- Check:
php artisan list | grep claude - Fix: Run
composer dump-autoload
Issue 2: Database connection failed
- Solution: Check .env configuration
- Verify:
php artisan config:cache - Test:
php artisan tinkerthenDB::connection()->getPdo()
Issue 3: Permission denied on output
- Solution: Check write permissions
- Fix:
mkdir -p api/docs && chmod 755 api/docs
Issue 4: Memory exhausted
- Solution: Increase PHP memory limit
- Fix: Add to .env:
PHP_MEMORY_LIMIT=512M
Related Commands
/getdb:mysql: Direct MySQL documentation (faster, simpler)/migrate: Run database migrations/check: Validate database structure
