spatie/laravel-model-info
Inspect Laravel Eloquent models to discover their file name, table name, attributes (name/type) and relations (name/type/related model). Also includes a ModelFinder to automatically locate all models in your application.
App\Models\* namespace).append(), hidden(), or magic methods (e.g., getAttribute()).getXAttribute()/setXAttribute() unless explicitly parsed (package uses get_defined_vars() + get_class_vars()).morphTo) without additional logic.ModelInfo instances (e.g., via Laravel’s cache or a singleton service).HasFactory or similar proxies.ModelInfo be queried? Can results be cached?spatie/laravel-medialibrary or filamentphp/filament for UI generation.darkaonline/l5-swagger or zircote/swagger-php for auto-docs.pestphp/pest or phpunit to assert model schemas.User) to validate accuracy and performance.ModelInfo.ModelInfo results to mitigate reflection overhead.fallback() method in your wrapper to return cached/predefined data if reflection fails.asJson()) unless they modify $fillable/$casts.composer require spatie/laravel-model-info
Publish config if extending defaults (though none exist by default).class EnhancedModelInfo {
public static function forModel(string $modelClass): ModelInfo {
return cache()->remember("model_info.{$modelClass}", now()->addHours(1), fn() =>
ModelInfo::forModel($modelClass)
);
}
}
EnhancedModelInfo to the container.ModelInfo failures (e.g., missing models, parsing errors).dd(ModelInfo::forModel(YourModel::class)->toArray()).ModelInfo results in Redis/Memcached for >100ms response times.ModelInfo in loops (e.g., preload all models at app boot).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Reflection parsing fails | Missing metadata for a model | Fallback to cached/predefined data |
| Model namespace changes | ModelInfo returns stale data |
Invalidate cache on model changes (e.g., via ModelEvent::saved) |
| PHP version incompatibility | Package breaks | Pin PHP version in composer.json |
| Dynamic properties ignored | Incomplete attribute/relation lists | Supplement with manual annotations |
ModelInfo for custom logic (e.g., filtering sensitive fields).ModelInfo::forModel() calls).How can I help you explore Laravel packages today?