Laravel-specific analyzer module for detecting and extracting framework features.
This module provides framework-aware analysis on top of the base PHP analyzer. It detects Laravel-specific patterns and extracts ORM relationships, controller actions, routes, and other framework features.
laravel/
├── types.go - Laravel-specific type definitions
├── analyzer.go - Main Laravel analyzer coordinator
├── eloquent.go - Eloquent Model analyzer
├── controller.go - Controller analyzer
└── routes.go - Route file parser (TODO)
Illuminate\Database\Eloquent\Model$fillable - mass assignable attributes$guarded - protected attributes$casts - attribute type casting$hidden - hidden attributes for serialization$table - custom table name$primaryKey - custom primary keyscopeMethodName)getXxxAttribute, setXxxAttribute)hasOne() - one-to-onehasMany() - one-to-manybelongsTo() - inverse one-to-manybelongsToMany() - many-to-manyhasManyThrough() - has-many-throughApp\Http\Controllers namespaceroutes/web.php and routes/api.phpimport (
"github.com/doITmagic/rag-code-mcp/internal/ragcode/analyzers/php"
"github.com/doITmagic/rag-code-mcp/internal/ragcode/analyzers/php/laravel"
)
// First, analyze PHP code
phpAnalyzer := php.NewCodeAnalyzer()
packageInfo, err := phpAnalyzer.AnalyzePath("app/Models")
// Then apply Laravel-specific analysis
laravelAnalyzer := laravel.NewAnalyzer(packageInfo)
laravelInfo := laravelAnalyzer.Analyze()
// Access Laravel-specific features
for _, model := range laravelInfo.Models {
fmt.Printf("Model: %s\n", model.ClassName)
fmt.Printf(" Table: %s\n", model.Table)
fmt.Printf(" Fillable: %v\n", model.Fillable)
for _, relation := range model.Relations {
fmt.Printf(" Relation: %s -> %s (%s)\n",
relation.Name, relation.RelatedModel, relation.Type)
}
}
// The Laravel analyzer works as a decorator over PHP analyzer
phpAnalyzer := php.NewCodeAnalyzer()
pkgInfo, _ := phpAnalyzer.AnalyzePath("app/")
// Detect if it's a Laravel project
isLaravel := detectLaravelProject(pkgInfo)
if isLaravel {
laravelAnalyzer := laravel.NewAnalyzer(pkgInfo)
laravelInfo := laravelAnalyzer.Analyze()
// Use Laravel-specific information for better RAG chunking
chunks := createLaravelAwareChunks(pkgInfo, laravelInfo)
}
Base PHP AST → PHP Analyzer → Laravel Analyzer → RAG Chunks
The analyzer uses multiple signals to detect Laravel:
extends Model, extends Controller)App\Models\, App\Http\Controllers\)app/Models/, routes/)SoftDeletes, Notifiable)Instead of arbitrary character limits, chunks are created based on:
$fillable = ['name', 'email'] → Need to parse array literalsreturn $this->hasMany(Post::class) → Need to parse method callsRoute::get() calls# Run Laravel analyzer tests
go test ./internal/ragcode/analyzers/php/laravel/
# Test with real Laravel project
go test -v -run TestLaravelProjectAnalysis
See laravel/examples/ for sample Laravel code and expected analysis output.
When adding new Laravel features:
types.gomiddleware.go)analyzer.go