JSON Output

Use --format=json to get machine-readable output, perfect for CI/CD pipelines.

$ php artisan model-analyzer:analyze --format=json

CI/CD Integration

The JSON output includes a top-level health_score field. You can parse this in your pipeline and fail the build if the score drops below your threshold. Combine with --strict to get a non-zero exit code on any issue.

{
  "health_score": 62,
  "rating": "FAIR",
  "models_scanned": 6,
  "total_relationships": 16,
  "issues": {
    "errors": [
      {
        "model": "Product",
        "relationship": "belongsTo(Category)",
        "type": "missing_column",
        "message": "Column `category_id` not found on `products` table",
        "severity": "error"
      }
    ],
    "warnings": [
      {
        "model": "Post",
        "column": "editor_id",
        "type": "missing_index",
        "message": "Column `editor_id` has no index (performance risk)",
        "severity": "warning"
      },
      {
        "model": "Comment",
        "relationship": "hasOne(Reaction)",
        "type": "missing_inverse",
        "message": "No inverse relationship found on Reaction model",
        "severity": "warning"
      }
    ]
  },
  "breakdown": {
    "inverse_relationships": { "score": 30, "max": 30 },
    "no_circular_deps": { "score": 30, "max": 30 },
    "column_existence": { "score": 10, "max": 20 },
    "foreign_key_indexes": { "score": 8, "max": 10 },
    "foreign_key_constraints": { "score": 4, "max": 10 }
  },
  "models": [
    { "name": "User", "namespace": "App\\Models\\User", "relationships": 4, "status": "ok" },
    { "name": "Post", "namespace": "App\\Models\\Post", "relationships": 4, "status": "warning" },
    { "name": "Comment", "namespace": "App\\Models\\Comment", "relationships": 3, "status": "warning" },
    { "name": "Tag", "namespace": "App\\Models\\Tag", "relationships": 1, "status": "ok" },
    { "name": "Order", "namespace": "App\\Models\\Order", "relationships": 2, "status": "ok" },
    { "name": "Product", "namespace": "App\\Models\\Product", "relationships": 2, "status": "error" }
  ]
}

Example: GitHub Actions

- name: Check model health
  run: |
    SCORE=$(php artisan model-analyzer:analyze --format=json | jq '.health_score')
    if [ "$SCORE" -lt 80 ]; then
      echo "Health score $SCORE is below threshold (80)"
      exit 1
    fi