laravel-devtoolbox-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Laravel Devtoolbox CLI

Laravel Devtoolbox CLI

Skill by ara.so — Devtools Skills collection.
Laravel Devtoolbox is a comprehensive CLI toolkit for Laravel applications that provides deep introspection, analysis, and debugging capabilities. It helps developers scan models, routes, services, database queries, security issues, and performance bottlenecks directly from the command line.
ara.so开发的技能工具——Devtools技能集合。
Laravel Devtoolbox是一款面向Laravel应用的综合CLI工具包,提供深度内省、分析和调试功能。它帮助开发者直接从命令行扫描模型、路由、服务、数据库查询、安全问题和性能瓶颈。

Installation

安装

Install as a development dependency via Composer:
bash
composer require --dev grazulex/laravel-devtoolbox
Requirements:
  • PHP 8.3+
  • Laravel 11.x or 12.x
通过Composer作为开发依赖安装:
bash
composer require --dev grazulex/laravel-devtoolbox
要求:
  • PHP 8.3+
  • Laravel 11.x 或 12.x

Core Concepts

核心概念

Laravel Devtoolbox provides multiple categories of analysis commands:
  1. Application Scanning - Comprehensive health checks and overview
  2. Model Analysis - Eloquent models, relationships, and usage
  3. Route Analysis - Route inspection, unused detection, reverse lookup
  4. Database Analysis - SQL tracing, N+1 detection, column usage
  5. Security Analysis - Unprotected routes, middleware coverage
  6. Performance Analysis - Memory, slow queries, cache, queue analysis
  7. Container Analysis - Service bindings, providers, dependency injection
All commands support multiple output formats:
array
(default),
json
,
count
,
mermaid
.
Laravel Devtoolbox提供多类分析命令:
  1. 应用扫描 - 全面的健康检查和概览
  2. 模型分析 - Eloquent模型、关联关系及使用情况
  3. 路由分析 - 路由检查、未使用路由检测、反向查找
  4. 数据库分析 - SQL追踪、N+1问题检测、列使用情况
  5. 安全分析 - 未受保护的路由、中间件覆盖情况
  6. 性能分析 - 内存、慢查询、缓存、队列分析
  7. 容器分析 - 服务绑定、服务提供者、依赖注入
所有命令支持多种输出格式:
array
(默认)、
json
count
mermaid

Key Commands

核心命令

Application Overview & Scanning

应用概览与扫描

bash
undefined
bash
undefined

Enhanced application overview

增强版应用概览

php artisan dev:about+ --extended --performance
php artisan dev:about+ --extended --performance

Comprehensive scan of all aspects

全面扫描所有方面

php artisan dev:scan --all
php artisan dev:scan --all

Specific scanners

指定扫描项

php artisan dev:scan --models --routes --services
undefined
php artisan dev:scan --models --routes --services
undefined

Model Analysis

模型分析

bash
undefined
bash
undefined

List all Eloquent models

列出所有Eloquent模型

php artisan dev:models
php artisan dev:models

Export models to JSON

将模型导出为JSON

php artisan dev:models --format=json --output=models.json
php artisan dev:models --format=json --output=models.json

Find where a specific model is used

查找特定模型的使用位置

php artisan dev:model:where-used App\Models\User
php artisan dev:model:where-used App\Models\User

Generate relationship diagram (Mermaid format)

生成关联关系图(Mermaid格式)

php artisan dev:model:graph --format=mermaid --output=relationships.mmd
undefined
php artisan dev:model:graph --format=mermaid --output=relationships.mmd
undefined

Route Analysis

路由分析

bash
undefined
bash
undefined

List all routes with details

列出所有路由及详细信息

php artisan dev:routes
php artisan dev:routes

Find unused routes

查找未使用的路由

php artisan dev:routes:unused
php artisan dev:routes:unused

Find routes by controller (reverse lookup)

通过控制器查找路由(反向查找)

php artisan dev:routes:where UserController
php artisan dev:routes:where UserController

Export unused routes to JSON

将未使用路由导出为JSON

php artisan dev:routes:unused --format=json --output=unused-routes.json
undefined
php artisan dev:routes:unused --format=json --output=unused-routes.json
undefined

Database & SQL Analysis

数据库与SQL分析

bash
undefined
bash
undefined

Trace SQL queries for a specific route

追踪特定路由的SQL查询

php artisan dev:sql:trace --route=dashboard
php artisan dev:sql:trace --route=dashboard

Analyze for N+1 problems and duplicates

分析N+1问题和重复查询

php artisan dev:sql:duplicates --route=users.index --threshold=3
php artisan dev:sql:duplicates --route=users.index --threshold=3

Check column usage across codebase

检查代码库中列的使用情况

php artisan dev:db:column-usage --unused-only
php artisan dev:db:column-usage --unused-only

Detect slow queries

检测慢查询

php artisan dev:performance:slow-queries --threshold=1000
undefined
php artisan dev:performance:slow-queries --threshold=1000
undefined

Security Analysis

安全分析

bash
undefined
bash
undefined

Find unprotected routes

查找未受保护的路由

php artisan dev:security:unprotected-routes
php artisan dev:security:unprotected-routes

Show only critical unprotected routes

仅显示关键的未受保护路由

php artisan dev:security:unprotected-routes --critical-only
php artisan dev:security:unprotected-routes --critical-only

Export security scan

导出安全扫描结果

php artisan dev:security:unprotected-routes --format=json --output=security-audit.json
undefined
php artisan dev:security:unprotected-routes --format=json --output=security-audit.json
undefined

Performance Analysis

性能分析

bash
undefined
bash
undefined

Analyze memory usage for a route

分析特定路由的内存使用情况

php artisan dev:performance:memory --route=dashboard
php artisan dev:performance:memory --route=dashboard

Find slow database queries

查找慢数据库查询

php artisan dev:performance:slow-queries --threshold=1000
php artisan dev:performance:slow-queries --threshold=1000

Analyze cache performance

分析缓存性能

php artisan dev:cache:analysis --drivers=redis,file
php artisan dev:cache:analysis --drivers=redis,file

Analyze queue performance

分析队列性能

php artisan dev:queue:analysis --failed-jobs --slow-jobs
undefined
php artisan dev:queue:analysis --failed-jobs --slow-jobs
undefined

Service Container & Providers

服务容器与服务提供者

bash
undefined
bash
undefined

List service container bindings

列出服务容器绑定

php artisan dev:services
php artisan dev:services

Analyze container bindings with resolution details

分析容器绑定及解析详情

php artisan dev:container:bindings --show-resolved
php artisan dev:container:bindings --show-resolved

Service provider performance timeline

服务提供者性能时间线

php artisan dev:providers:timeline --slow-threshold=100
php artisan dev:providers:timeline --slow-threshold=100

List middleware usage

列出中间件使用情况

php artisan dev:middleware
php artisan dev:middleware

Find where middleware is used

查找中间件的使用位置

php artisan dev:middlewares:where-used auth
undefined
php artisan dev:middlewares:where-used auth
undefined

Environment & Configuration

环境与配置

bash
undefined
bash
undefined

Compare environment files

比较环境文件

php artisan dev:env:diff --against=.env.example
php artisan dev:env:diff --against=.env.example

Monitor logs in real-time

实时监控日志

php artisan dev:log:tail --follow --level=error
php artisan dev:log:tail --follow --level=error

List all views

列出所有视图

php artisan dev:views
undefined
php artisan dev:views
undefined

Configuration

配置

Publish the configuration file:
bash
php artisan vendor:publish --tag=devtoolbox-config
This creates
config/devtoolbox.php
:
php
<?php

return [
    /*
     | Default output format for commands
     | Options: 'array', 'json', 'count', 'mermaid'
     */
    'default_format' => env('DEVTOOLBOX_FORMAT', 'array'),

    /*
     | Scanner-specific options
     */
    'scanners' => [
        'models' => [
            'enabled' => true,
            'paths' => [app_path('Models')],
        ],
        'routes' => [
            'enabled' => true,
            'exclude_patterns' => ['debugbar.*', 'telescope.*'],
        ],
        'performance' => [
            'slow_query_threshold' => 1000, // milliseconds
            'memory_limit_warning' => 128, // MB
        ],
    ],

    /*
     | Export settings
     */
    'export' => [
        'default_path' => storage_path('devtoolbox'),
        'json_pretty_print' => true,
    ],
];
发布配置文件:
bash
php artisan vendor:publish --tag=devtoolbox-config
这会创建
config/devtoolbox.php
php
<?php

return [
    /*
     | 命令的默认输出格式
     | 选项: 'array', 'json', 'count', 'mermaid'
     */
    'default_format' => env('DEVTOOLBOX_FORMAT', 'array'),

    /*
     | 扫描器特定选项
     */
    'scanners' => [
        'models' => [
            'enabled' => true,
            'paths' => [app_path('Models')],
        ],
        'routes' => [
            'enabled' => true,
            'exclude_patterns' => ['debugbar.*', 'telescope.*'],
        ],
        'performance' => [
            'slow_query_threshold' => 1000, // 毫秒
            'memory_limit_warning' => 128, // MB
        ],
    ],

    /*
     | 导出设置
     */
    'export' => [
        'default_path' => storage_path('devtoolbox'),
        'json_pretty_print' => true,
    ],
];

Common Patterns

常见模式

Daily Development Workflow

日常开发工作流

bash
#!/bin/bash
bash
#!/bin/bash

daily-check.sh - Run daily health checks

daily-check.sh - 运行日常健康检查

echo "=== Application Health Check ==="
echo "=== 应用健康检查 ==="

Quick overview

快速概览

php artisan dev:about+ --extended
php artisan dev:about+ --extended

Count unused routes

统计未使用路由

echo "Unused routes:" php artisan dev:routes:unused --format=count
echo "未使用路由:" php artisan dev:routes:unused --format=count

Check for unprotected routes

检查未受保护路由

echo "Unprotected routes:" php artisan dev:security:unprotected-routes --format=count
echo "未受保护路由:" php artisan dev:security:unprotected-routes --format=count

Compare env files

比较环境文件

echo "Environment differences:" php artisan dev:env:diff --against=.env.example
undefined
echo "环境文件差异:" php artisan dev:env:diff --against=.env.example
undefined

CI/CD Quality Gates

CI/CD质量门

bash
#!/bin/bash
bash
#!/bin/bash

ci-quality-check.sh - CI/CD integration script

ci-quality-check.sh - CI/CD集成脚本

Generate reports

生成报告

php artisan dev:scan --all --format=json --output=reports/scan.json php artisan dev:routes:unused --format=json --output=reports/unused-routes.json php artisan dev:security:unprotected-routes --format=json --output=reports/security.json
php artisan dev:scan --all --format=json --output=reports/scan.json php artisan dev:routes:unused --format=json --output=reports/unused-routes.json php artisan dev:security:unprotected-routes --format=json --output=reports/security.json

Check thresholds

检查阈值

UNUSED_ROUTES=$(php artisan dev:routes:unused --format=count | jq -r '.count') UNPROTECTED_ROUTES=$(php artisan dev:security:unprotected-routes --format=count | jq -r '.count')
echo "Unused routes: $UNUSED_ROUTES" echo "Unprotected routes: $UNPROTECTED_ROUTES"
UNUSED_ROUTES=$(php artisan dev:routes:unused --format=count | jq -r '.count') UNPROTECTED_ROUTES=$(php artisan dev:security:unprotected-routes --format=count | jq -r '.count')
echo "未使用路由: $UNUSED_ROUTES" echo "未受保护路由: $UNPROTECTED_ROUTES"

Fail if thresholds exceeded

超过阈值则失败

if [ "$UNUSED_ROUTES" -gt 10 ]; then echo "❌ Too many unused routes: $UNUSED_ROUTES (max: 10)" exit 1 fi
if [ "$UNPROTECTED_ROUTES" -gt 5 ]; then echo "❌ Too many unprotected routes: $UNPROTECTED_ROUTES (max: 5)" exit 1 fi
echo "✅ Quality checks passed"
undefined
if [ "$UNUSED_ROUTES" -gt 10 ]; then echo "❌ 未使用路由过多: $UNUSED_ROUTES (最大值: 10)" exit 1 fi
if [ "$UNPROTECTED_ROUTES" -gt 5 ]; then echo "❌ 未受保护路由过多: $UNPROTECTED_ROUTES (最大值: 5)" exit 1 fi
echo "✅ 质量检查通过"
undefined

Generate Documentation

生成文档

bash
#!/bin/bash
bash
#!/bin/bash

generate-docs.sh - Auto-generate project documentation

generate-docs.sh - 自动生成项目文档

mkdir -p docs/architecture
mkdir -p docs/architecture

Generate model documentation

生成模型文档

php artisan dev:models --format=json --output=docs/architecture/models.json
php artisan dev:models --format=json --output=docs/architecture/models.json

Generate relationship diagram

生成关联关系图

php artisan dev:model:graph --format=mermaid --output=docs/architecture/relationships.mmd
php artisan dev:model:graph --format=mermaid --output=docs/architecture/relationships.mmd

Generate route documentation

生成路由文档

php artisan dev:routes --format=json --output=docs/architecture/routes.json
php artisan dev:routes --format=json --output=docs/architecture/routes.json

Generate service bindings

生成服务绑定文档

php artisan dev:container:bindings --format=json --output=docs/architecture/bindings.json
echo "✅ Documentation generated in docs/architecture/"
undefined
php artisan dev:container:bindings --format=json --output=docs/architecture/bindings.json
echo "✅ 文档已生成在docs/architecture/"
undefined

Performance Debugging Session

性能调试会话

php
<?php
// Example: Debug performance issues for a specific route

// 1. Trace SQL queries
// php artisan dev:sql:trace --route=users.index

// 2. Check for N+1 problems
// php artisan dev:sql:duplicates --route=users.index --threshold=3

// 3. Analyze memory usage
// php artisan dev:performance:memory --route=users.index

// 4. Find slow queries
// php artisan dev:performance:slow-queries --threshold=500

// 5. Check cache configuration
// php artisan dev:cache:analysis --drivers=redis
php
<?php
// 示例: 调试特定路由的性能问题

// 1. 追踪SQL查询
// php artisan dev:sql:trace --route=users.index

// 2. 检查N+1问题
// php artisan dev:sql:duplicates --route=users.index --threshold=3

// 3. 分析内存使用情况
// php artisan dev:performance:memory --route=users.index

// 4. 查找慢查询
// php artisan dev:performance:slow-queries --threshold=500

// 5. 检查缓存配置
// php artisan dev:cache:analysis --drivers=redis

Model Usage Analysis

模型使用分析

bash
undefined
bash
undefined

Find all places where User model is used

查找User模型的所有使用位置

php artisan dev:model:where-used App\Models\User
php artisan dev:model:where-used App\Models\User

Generate relationships for specific models

为特定模型生成关联关系图

php artisan dev:model:graph --format=mermaid --models=User,Post,Comment
php artisan dev:model:graph --format=mermaid --models=User,Post,Comment

Export model analysis

导出模型分析结果

php artisan dev:models --format=json | jq '.[] | select(.relationships | length > 5)'
undefined
php artisan dev:models --format=json | jq '.[] | select(.relationships | length > 5)'
undefined

Security Audit

安全审计

bash
#!/bin/bash
bash
#!/bin/bash

security-audit.sh - Complete security check

security-audit.sh - 完整安全检查

echo "=== Security Audit ==="
echo "=== 安全审计 ==="

Find unprotected routes

查找未受保护路由

php artisan dev:security:unprotected-routes --format=json --output=security/unprotected.json
php artisan dev:security:unprotected-routes --format=json --output=security/unprotected.json

Check middleware usage

检查中间件使用情况

php artisan dev:middleware --format=json --output=security/middleware.json
php artisan dev:middleware --format=json --output=security/middleware.json

Analyze route protection patterns

分析路由保护模式

php artisan dev:routes --format=json |
jq '[.[] | select(.middleware | index("auth") | not)]' > security/no-auth.json
echo "Security reports saved to security/"
undefined
php artisan dev:routes --format=json |
jq '[.[] | select(.middleware | index("auth") | not)]' > security/no-auth.json
echo "安全报告已保存到security/"
undefined

Real-World Examples

实际案例

Example 1: Finding N+1 Query Problems

案例1:查找N+1查询问题

bash
undefined
bash
undefined

Run the N+1 detector on a specific route

在特定路由上运行N+1检测器

php artisan dev:sql:duplicates --route=posts.index --threshold=3
php artisan dev:sql:duplicates --route=posts.index --threshold=3

Output shows:

输出显示:

- Duplicate queries

- 重复查询

- Number of times each query runs

- 每个查询的运行次数

- Suggested eager loading solutions

- 建议的预加载解决方案


**Fix in Controller:**

```php
<?php

namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        // ❌ Before (N+1 problem)
        // $posts = Post::all();
        
        // ✅ After (eager loading based on dev:sql:duplicates suggestion)
        $posts = Post::with(['author', 'comments.user'])->get();
        
        return view('posts.index', compact('posts'));
    }
}

**控制器中的修复:**

```php
<?php

namespace App\Http\Controllers;

use App\Models\Post;

class PostController extends Controller
{
    public function index()
    {
        // ❌ 修复前(存在N+1问题)
        // $posts = Post::all();
        
        // ✅ 修复后(根据dev:sql:duplicates建议进行预加载)
        $posts = Post::with(['author', 'comments.user'])->get();
        
        return view('posts.index', compact('posts'));
    }
}

Example 2: Cleaning Up Unused Routes

案例2:清理未使用路由

bash
undefined
bash
undefined

Find unused routes

查找未使用路由

php artisan dev:routes:unused --format=json --output=cleanup/unused-routes.json
php artisan dev:routes:unused --format=json --output=cleanup/unused-routes.json

Review the list and remove from routes/web.php

查看列表并从routes/web.php中删除

cat cleanup/unused-routes.json | jq -r '.[] | .name'

**Before cleanup:**

```php
<?php
// routes/web.php

Route::get('/old-dashboard', [OldDashboardController::class, 'index'])->name('old.dashboard');
Route::get('/legacy-users', [LegacyUserController::class, 'index'])->name('legacy.users');
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
After cleanup (remove unused routes):
php
<?php
// routes/web.php

Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
cat cleanup/unused-routes.json | jq -r '.[] | .name'

**清理前:**

```php
<?php
// routes/web.php

Route::get('/old-dashboard', [OldDashboardController::class, 'index'])->name('old.dashboard');
Route::get('/legacy-users', [LegacyUserController::class, 'index'])->name('legacy.users');
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
清理后(移除未使用路由):
php
<?php
// routes/web.php

Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

Example 3: Documenting Application Architecture

案例3:记录应用架构

bash
undefined
bash
undefined

Generate complete architecture documentation

生成完整的架构文档

mkdir -p docs/architecture
php artisan dev:models --format=json --output=docs/architecture/models.json php artisan dev:model:graph --format=mermaid --output=docs/architecture/relationships.mmd php artisan dev:routes --format=json --output=docs/architecture/routes.json php artisan dev:services --format=json --output=docs/architecture/services.json

**Use Mermaid diagram in README.md:**

```markdown
mkdir -p docs/architecture
php artisan dev:models --format=json --output=docs/architecture/models.json php artisan dev:model:graph --format=mermaid --output=docs/architecture/relationships.mmd php artisan dev:routes --format=json --output=docs/architecture/routes.json php artisan dev:services --format=json --output=docs/architecture/services.json

**在README.md中使用Mermaid图:**

```markdown

Application Architecture

应用架构

Model Relationships

模型关联关系

mermaid
{{< include docs/architecture/relationships.mmd >}}
undefined
mermaid
{{< include docs/architecture/relationships.mmd >}}
undefined

Example 4: Performance Monitoring Script

案例4:性能监控脚本

php
<?php
// scripts/performance-check.php

// Run this script before deployment
$routes = [
    'home',
    'dashboard',
    'users.index',
    'posts.index',
];

foreach ($routes as $route) {
    echo "Checking route: $route\n";
    
    // Check memory usage
    shell_exec("php artisan dev:performance:memory --route=$route");
    
    // Check SQL queries
    shell_exec("php artisan dev:sql:duplicates --route=$route --threshold=3");
    
    echo "\n";
}
php
<?php
// scripts/performance-check.php

// 部署前运行此脚本
$routes = [
    'home',
    'dashboard',
    'users.index',
    'posts.index',
];

foreach ($routes as $route) {
    echo "检查路由: $route\n";
    
    // 检查内存使用情况
    shell_exec("php artisan dev:performance:memory --route=$route");
    
    // 检查SQL查询
    shell_exec("php artisan dev:sql:duplicates --route=$route --threshold=3");
    
    echo "\n";
}

Example 5: Automated Security Checks

案例5:自动化安全检查

yaml
undefined
yaml
undefined

.github/workflows/security-scan.yml

.github/workflows/security-scan.yml

name: Security Scan
on: [push, pull_request]
jobs: security: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
  - name: Setup PHP
    uses: shivammathur/setup-php@v2
    with:
      php-version: '8.3'
  
  - name: Install dependencies
    run: composer install --prefer-dist --no-progress
  
  - name: Run security scan
    run: |
      php artisan dev:security:unprotected-routes --format=json > security-report.json
      UNPROTECTED=$(jq 'length' security-report.json)
      echo "Found $UNPROTECTED unprotected routes"
      if [ "$UNPROTECTED" -gt 5 ]; then
        echo "::error::Too many unprotected routes: $UNPROTECTED"
        exit 1
      fi
  
  - name: Upload security report
    uses: actions/upload-artifact@v3
    with:
      name: security-report
      path: security-report.json
undefined
name: Security Scan
on: [push, pull_request]
jobs: security: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3
  - name: Setup PHP
    uses: shivammathur/setup-php@v2
    with:
      php-version: '8.3'
  
  - name: Install dependencies
    run: composer install --prefer-dist --no-progress
  
  - name: Run security scan
    run: |
      php artisan dev:security:unprotected-routes --format=json > security-report.json
      UNPROTECTED=$(jq 'length' security-report.json)
      echo "Found $UNPROTECTED unprotected routes"
      if [ "$UNPROTECTED" -gt 5 ]; then
        echo "::error::Too many unprotected routes: $UNPROTECTED"
        exit 1
      fi
  
  - name: Upload security report
    uses: actions/upload-artifact@v3
    with:
      name: security-report
      path: security-report.json
undefined

Troubleshooting

故障排除

Command Not Found

命令未找到

If
dev:*
commands are not available:
bash
undefined
如果
dev:*
命令不可用:
bash
undefined

Clear cache and reload

清除缓存并重新加载

php artisan clear-compiled php artisan config:clear php artisan cache:clear composer dump-autoload
php artisan clear-compiled php artisan config:clear php artisan cache:clear composer dump-autoload

Verify installation

验证安装

composer show grazulex/laravel-devtoolbox
undefined
composer show grazulex/laravel-devtoolbox
undefined

Memory Issues with Large Applications

大型应用的内存问题

For large applications, increase memory limit:
bash
php -d memory_limit=512M artisan dev:scan --all
对于大型应用,增加内存限制:
bash
php -d memory_limit=512M artisan dev:scan --all

Or set in php.ini

或在php.ini中设置

memory_limit = 512M
undefined
memory_limit = 512M
undefined

Performance Issues with SQL Tracing

SQL追踪的性能问题

SQL tracing can be slow on routes with many queries:
bash
undefined
在查询较多的路由上,SQL追踪可能较慢:
bash
undefined

Use threshold to focus on problematic queries

使用阈值聚焦有问题的查询

php artisan dev:sql:duplicates --route=users.index --threshold=5
undefined
php artisan dev:sql:duplicates --route=users.index --threshold=5
undefined

JSON Output Parsing

JSON输出解析

When using JSON output in scripts:
bash
undefined
在脚本中使用JSON输出时:
bash
undefined

Pretty print JSON

格式化JSON

php artisan dev:models --format=json | jq '.'
php artisan dev:models --format=json | jq '.'

Extract specific fields

提取特定字段

php artisan dev:routes:unused --format=json | jq -r '.[] | .name'
php artisan dev:routes:unused --format=json | jq -r '.[] | .name'

Count results

统计结果

php artisan dev:models --format=json | jq 'length'
undefined
php artisan dev:models --format=json | jq 'length'
undefined

Mermaid Diagram Rendering

Mermaid图渲染

If Mermaid diagrams are too large:
bash
undefined
如果Mermaid图过大:
bash
undefined

Focus on specific models

聚焦特定模型

php artisan dev:model:graph --format=mermaid --models=User,Post,Comment
php artisan dev:model:graph --format=mermaid --models=User,Post,Comment

Use online editors

使用在线编辑器

Copy output to https://mermaid.live/

将输出复制到https://mermaid.live/

undefined
undefined

Export Path Issues

导出路径问题

If output files fail to save:
bash
undefined
如果输出文件保存失败:
bash
undefined

Ensure directory exists and is writable

确保目录存在且可写

mkdir -p storage/devtoolbox chmod -R 775 storage/devtoolbox
mkdir -p storage/devtoolbox chmod -R 775 storage/devtoolbox

Or use absolute path

或使用绝对路径

php artisan dev:models --format=json --output=/tmp/models.json
undefined
php artisan dev:models --format=json --output=/tmp/models.json
undefined

Integration Examples

集成示例

Laravel Telescope Integration

Laravel Telescope集成

php
<?php
// Use alongside Telescope for deeper analysis

// 1. Enable Telescope query logging
// 2. Run dev:sql:trace to get query details
// 3. Compare results in Telescope UI

// Telescope shows runtime queries, DevToolbox shows code analysis
php
<?php
// 与Telescope配合使用以进行更深入的分析

// 1. 启用Telescope查询日志
// 2. 运行dev:sql:trace获取查询详情
// 3. 在Telescope界面中比较结果

// Telescope显示运行时查询,DevToolbox显示代码分析

PHPStan/Larastan Integration

PHPStan/Larastan集成

bash
undefined
bash
undefined

Use DevToolbox to find issues, PHPStan to prevent them

使用DevToolbox查找问题,PHPStan预防问题

Find unused code

查找未使用代码

php artisan dev:routes:unused > unused.txt php artisan dev:db:column-usage --unused-only > unused-columns.txt
php artisan dev:routes:unused > unused.txt php artisan dev:db:column-usage --unused-only > unused-columns.txt

Then configure PHPStan rules based on findings

根据发现配置PHPStan规则

undefined
undefined

Monitoring Dashboard Integration

监控仪表板集成

bash
#!/bin/bash
bash
#!/bin/bash

monitoring/collect-metrics.sh

monitoring/collect-metrics.sh

Collect metrics for monitoring dashboard

收集指标用于监控仪表板

php artisan dev:scan --all --format=json > /var/metrics/laravel-scan.json php artisan dev:performance:slow-queries --threshold=1000 --format=json > /var/metrics/slow-queries.json php artisan dev:cache:analysis --format=json > /var/metrics/cache-analysis.json
php artisan dev:scan --all --format=json > /var/metrics/laravel-scan.json php artisan dev:performance:slow-queries --threshold=1000 --format=json > /var/metrics/slow-queries.json php artisan dev:cache:analysis --format=json > /var/metrics/cache-analysis.json

Send to monitoring service

发送到监控服务

curl -X POST https://monitoring.example.com/metrics
-H "Content-Type: application/json"
-d @/var/metrics/laravel-scan.json
undefined
curl -X POST https://monitoring.example.com/metrics
-H "Content-Type: application/json"
-d @/var/metrics/laravel-scan.json
undefined

Best Practices

最佳实践

  1. Run in Development Only - This package is designed for dev environments
  2. Use JSON for Automation - Always use
    --format=json
    in CI/CD scripts
  3. Regular Health Checks - Run
    dev:scan --all
    weekly to catch issues early
  4. Document Architecture - Use
    dev:model:graph
    to maintain architecture diagrams
  5. Security First - Run
    dev:security:unprotected-routes
    before deployments
  6. Performance Baseline - Establish baselines with
    dev:performance:*
    commands
  7. Version Control Reports - Commit generated JSON reports for historical tracking
  1. 仅在开发环境运行 - 此包专为开发环境设计
  2. 使用JSON进行自动化 - 在CI/CD脚本中始终使用
    --format=json
  3. 定期健康检查 - 每周运行
    dev:scan --all
    以提前发现问题
  4. 记录架构 - 使用
    dev:model:graph
    维护架构图
  5. 安全优先 - 部署前运行
    dev:security:unprotected-routes
  6. 性能基准 - 使用
    dev:performance:*
    命令建立基准
  7. 版本控制报告 - 将生成的JSON报告提交到版本控制以进行历史追踪