Loading...
Loading...
Swiss-army artisan CLI for Laravel to scan, inspect, debug, and explore every aspect of your Laravel application from the command line
npx skill4agent add aradotso/devtools-skills laravel-devtoolbox-cliSkill by ara.so — Devtools Skills collection.
composer require --dev grazulex/laravel-devtoolboxarrayjsoncountmermaid# Enhanced application overview
php artisan dev:about+ --extended --performance
# Comprehensive scan of all aspects
php artisan dev:scan --all
# Specific scanners
php artisan dev:scan --models --routes --services# List all Eloquent models
php artisan dev:models
# Export models to 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
# Generate relationship diagram (Mermaid format)
php artisan dev:model:graph --format=mermaid --output=relationships.mmd# List all routes with details
php artisan dev:routes
# Find unused routes
php artisan dev:routes:unused
# Find routes by controller (reverse lookup)
php artisan dev:routes:where UserController
# Export unused routes to JSON
php artisan dev:routes:unused --format=json --output=unused-routes.json# Trace SQL queries for a specific route
php artisan dev:sql:trace --route=dashboard
# Analyze for N+1 problems and duplicates
php artisan dev:sql:duplicates --route=users.index --threshold=3
# Check column usage across codebase
php artisan dev:db:column-usage --unused-only
# Detect slow queries
php artisan dev:performance:slow-queries --threshold=1000# Find unprotected routes
php artisan dev:security:unprotected-routes
# Show only critical unprotected routes
php artisan dev:security:unprotected-routes --critical-only
# Export security scan
php artisan dev:security:unprotected-routes --format=json --output=security-audit.json# Analyze memory usage for a route
php artisan dev:performance:memory --route=dashboard
# Find slow database queries
php artisan dev:performance:slow-queries --threshold=1000
# Analyze cache performance
php artisan dev:cache:analysis --drivers=redis,file
# Analyze queue performance
php artisan dev:queue:analysis --failed-jobs --slow-jobs# List service container bindings
php artisan dev:services
# Analyze container bindings with resolution details
php artisan dev:container:bindings --show-resolved
# Service provider performance timeline
php artisan dev:providers:timeline --slow-threshold=100
# List middleware usage
php artisan dev:middleware
# Find where middleware is used
php artisan dev:middlewares:where-used auth# Compare environment files
php artisan dev:env:diff --against=.env.example
# Monitor logs in real-time
php artisan dev:log:tail --follow --level=error
# List all views
php artisan dev:viewsphp artisan vendor:publish --tag=devtoolbox-configconfig/devtoolbox.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,
],
];#!/bin/bash
# daily-check.sh - Run daily health checks
echo "=== Application Health Check ==="
# Quick overview
php artisan dev:about+ --extended
# Count unused routes
echo "Unused routes:"
php artisan dev:routes:unused --format=count
# Check for unprotected routes
echo "Unprotected routes:"
php artisan dev:security:unprotected-routes --format=count
# Compare env files
echo "Environment differences:"
php artisan dev:env:diff --against=.env.example#!/bin/bash
# ci-quality-check.sh - CI/CD integration script
# 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
# 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"
# 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"#!/bin/bash
# generate-docs.sh - Auto-generate project documentation
mkdir -p docs/architecture
# Generate model documentation
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
# Generate route documentation
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/"<?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# Find all places where User model is used
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
# Export model analysis
php artisan dev:models --format=json | jq '.[] | select(.relationships | length > 5)'#!/bin/bash
# security-audit.sh - Complete security check
echo "=== Security Audit ==="
# Find unprotected routes
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
# 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/"# Run the N+1 detector on a specific route
php artisan dev:sql:duplicates --route=posts.index --threshold=3
# Output shows:
# - Duplicate queries
# - Number of times each query runs
# - Suggested eager loading solutions<?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'));
}
}# Find unused routes
php artisan dev:routes:unused --format=json --output=cleanup/unused-routes.json
# Review the list and remove from routes/web.php
cat cleanup/unused-routes.json | jq -r '.[] | .name'<?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
// routes/web.php
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');# 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# Application Architecture
## Model Relationships
```mermaid
{{< include docs/architecture/relationships.mmd >}}
### Example 4: Performance Monitoring Script
```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";
}# .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.jsondev:*# Clear cache and reload
php artisan clear-compiled
php artisan config:clear
php artisan cache:clear
composer dump-autoload
# Verify installation
composer show grazulex/laravel-devtoolboxphp -d memory_limit=512M artisan dev:scan --all
# Or set in php.ini
memory_limit = 512M# Use threshold to focus on problematic queries
php artisan dev:sql:duplicates --route=users.index --threshold=5# Pretty print JSON
php artisan dev:models --format=json | jq '.'
# Extract specific fields
php artisan dev:routes:unused --format=json | jq -r '.[] | .name'
# Count results
php artisan dev:models --format=json | jq 'length'# Focus on specific models
php artisan dev:model:graph --format=mermaid --models=User,Post,Comment
# Use online editors
# Copy output to https://mermaid.live/# Ensure directory exists and is writable
mkdir -p storage/devtoolbox
chmod -R 775 storage/devtoolbox
# Or use absolute path
php artisan dev:models --format=json --output=/tmp/models.json<?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# Use DevToolbox to find issues, PHPStan to prevent them
# Find unused code
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#!/bin/bash
# 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
# Send to monitoring service
curl -X POST https://monitoring.example.com/metrics \
-H "Content-Type: application/json" \
-d @/var/metrics/laravel-scan.json--format=jsondev:scan --alldev:model:graphdev:security:unprotected-routesdev:performance:*