Laravel Integration
DevDb Pro provides deep integration with Laravel, offering specialized features for Eloquent models, query optimization, and factory generation.
Features Overview
- Code Lens for Eloquent models
- One-click factory generation with real data
- MySQL query explainer for optimization
- Context menu integration
- Zero-config database discovery
Eloquent Model Code Lens
DevDb adds interactive Code Lens buttons directly above your Eloquent models.
View Table
Click "View table in DevDb" to:
- Instantly open the model's underlying table
- See live data from the database
- Edit records directly
Example:
// Click "View table in DevDb" appears above the class
class User extends Model
{
//...
}Generate Factory
Click "Generate factory" to:
- Auto-create a factory with real column names
- Pre-fill with sample data from existing records
- Match column types automatically
Example:
// Click "Generate factory" appears above the class
class Product extends Model
{
//...
}Generated factory:
<?php
namespace Database\Factories;
use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProductFactory extends Factory
{
protected $model = Product::class;
public function definition(): array
{
return [
'name' => $this->faker->words(3, true),
'description' => $this->faker->text(),
'price' => $this->faker->randomFloat(2, 10, 1000),
'stock_quantity' => $this->faker->numberBetween(0, 100),
'category_id' => \App\Models\Category::factory(),
'is_active' => $this->faker->boolean(),
'created_at' => now(),
'updated_at' => now(),
];
}
}Context Menu Integration
Right-click anywhere in your Laravel code to access DevDb features.
Open Table at Cursor
- Place cursor on a model class name
- Right-click → DevDb → "Open table at cursor"
- Table opens in DevDb
Works with:
- Model class names (
User,Product, etc.) - Table names in strings (
'users','products') - Eloquent relationships
Generate Factory from Cursor
- Place cursor on a model class name
- Right-click → DevDb → "Generate Laravel Factory"
- Factory is created with real schema
Query Explainer
Optimize MySQL queries using visual EXPLAIN integration.
How It Works
DevDb integrates with MySQL Visual Explain to analyze query execution plans.
Usage
From Code Lens:
- Select a SQL query in your code
- Click "Explain query" Code Lens
- View explanation in browser or copy URL
From Context Menu:
- Select a SQL query
- Right-click → DevDb → "Explain query"
- Analysis opens in browser
Supported Query Sources:
- Eloquent query builder
DBfacade queries- Raw SQL strings
Example:
// Select this query and click "Explain query"
DB::table('users')
->join('orders', 'users.id', '=', 'orders.user_id')
->where('users.is_active', true)
->get();What You Get
The explainer shows:
- Execution plan visualization
- Index usage analysis
- Join strategy details
- Performance bottlenecks
- Optimization suggestions
Zero-Config Database Discovery
DevDb automatically detects Laravel databases from .env configuration.
Supported Databases
- SQLite (default local database)
- MySQL/MariaDB
- PostgreSQL
- Microsoft SQL Server
How It Works
- DevDb reads your
.envfile - Extracts database credentials
- Auto-connects to the database
- No manual configuration needed
Example .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=my_laravel_app
DB_USERNAME=root
DB_PASSWORD=secretLaravel Sail Support
DevDb works with containerized Laravel (Sail):
- Detects Docker containers
- Reads docker-compose.yml
- Auto-connects to containerized database
- Dev container support included
Configuration
PHP Executable Path
For Laravel Artisan commands, configure PHP path:
- Open VS Code Settings
- Search for "DevDb PHP Executable"
- Set path (default:
php)
Examples:
- macOS with Homebrew:
/opt/homebrew/bin/php - DDEV:
ddev exec php - Custom:
/usr/local/bin/php8.2
Code Lens Settings
Enable/disable Code Lens for text selection:
- Open Settings
- Search for "DevDb Code Lens"
- Toggle "Enable Code Lens for Text Selection"
Workflow Examples
Example 1: Build a Feature
- Create model (
php artisan make:model Product) - Run migration
- Open DevDb, click "Generate factory" Code Lens
- Review factory, adjust if needed
- Seed data using factory
- Browse data in DevDb
Example 2: Debug Slow Query
- Write Eloquent query in controller
- Select the query
- Click "Explain query" Code Lens
- Review execution plan
- Add indexes based on recommendations
- Rerun explanation to verify improvement
Example 3: Inspect Relationships
- Open a model with relationships
- Click "View table in DevDb"
- Browse related records
- Verify foreign keys in schema tab
- Edit test data directly
Tips & Best Practices
Factory Generation
- Review generated factories before use
- Customize Faker methods for realistic data
- Add states for different scenarios
- Use relationships with
factory()method
Query Optimization
- Start with EXPLAIN before optimizing
- Focus on N+1 issues first
- Add indexes based on EXPLAIN output
- Re-test after changes
Model Development
- Use Code Lens to quickly verify table structure
- Check data directly from model file
- Generate factories early for testing
- Keep DevDb open while developing models
Team Collaboration
- Share factory patterns with team
- Document query optimizations in comments
- Use consistent Faker methods across factories
- Export seed data for shared fixtures
Troubleshooting
Code Lens Not Appearing
- Check PHP file is recognized (Laravel project)
- Verify class extends
Model - Restart VS Code extension host
- Check setting "Enable Code Lens" is on
Factory Generation Fails
- Verify PHP path in settings is correct
- Check Artisan is accessible
- Ensure factories folder exists
- Review output panel for errors
Query Explainer Issues
- Check query syntax is valid SQL
- Ensure MySQL database (explainer is MySQL-specific)
- Verify database connection is active
- Select full query including semicolon if needed
Next Steps
- Database Client - Master the interface
- MCP Server - AI integration
- Data Export - Export data
- Configuration - Advanced setup