- What is laravel/surveyor used for?
- Laravel Surveyor is a mostly static analysis tool that parses PHP files to extract metadata about classes, methods, properties, constants, return types, validation rules, and Eloquent model details. It exposes that metadata as structured ClassLikeResult objects so other tools can generate documentation, API contracts, TypeScript types, admin scaffolds, or IDE and agent tooling. It is designed for Laravel applications that need to introspect themselves, not as a generic PHP analysis component.
- How do I install Laravel Surveyor?
- Install it with Composer using composer require laravel/surveyor. It is an in-process library, so there is no separate service or CLI binary to configure. After installation you resolve the Analyzer from the Laravel container and pass it a file path or fully qualified class name.
- Does Laravel Surveyor require a database connection?
- Yes, Surveyor is only mostly static. It inspects Eloquent models, which means it opens a brief database connection, and it also reads container bindings for richer analysis. That makes output environment-dependent, so metadata can differ between local, CI, and staging environments if database or binding state differs.
- Can I use Laravel Surveyor outside a Laravel application?
- No. Surveyor must run inside a bootstrapped Laravel app because it reads container bindings and opens a database connection to inspect models. That rules out dropping it into a bare CLI script or a stateless worker. Use it as an artisan command or CI step rather than a runtime dependency in an unrelated PHP project.
- Is Laravel Surveyor production ready?
- Surveyor is currently in beta, and the README explicitly warns that the API will likely change before v1.0.0. Any code that directly touches Surveyor types is exposed to breaking changes, so pin an exact version and wrap Surveyor behind your own narrow interface returning your own DTOs. That adapter keeps a v1.0 upgrade, abandonment, or fork to a one-file swap rather than a large refactor.
- How does Laravel Surveyor perform and can I cache results?
- The maintainers state that performance is not where they want it yet, with slower execution and higher memory use than ideal. Treat caching as mandatory rather than an optimization; Surveyor supports an environment-configured cache via SURVEYOR_CACHE_ENABLED and SURVEYOR_CACHE_DIR. Spike against a representative app to record wall time, peak memory, and class count before committing to it in CI.
- What Laravel and PHP versions does Laravel Surveyor support?
- The provided material does not publish a fixed compatibility matrix, so verify Composer constraints per target application before committing. Beta packages often bump minimum PHP or Laravel versions in minor releases, so check every app you intend to analyze. Pin an exact Surveyor version and test upgrades deliberately.
- How do I analyze a file or class and get structured output from Surveyor?
- Resolve Laravel Surveyor's Analyzer from the container with app(Analyzer::class), then call analyze on a file path or fully qualified class name. The result exposes the analyzed scope and class result, including methods, properties, constants, validation rules, and a typed type graph. For other tools or polyglot pipelines, use the asArray or asJson serialization path instead of leaking Surveyor types directly.
- What is the difference between Laravel Surveyor and Laravel Ranger?
- Surveyor extracts detailed PHP and Laravel-specific metadata and exposes it in a structured format for other tools to consume. Laravel Ranger is the higher-level consumption layer that packages those results in detailed DTOs. If you need ready-shaped DTOs, check whether Ranger already provides the shaping layer you would otherwise build.
- How do I stop sensitive model fields from appearing in generated code with Surveyor?
- Surveyor's Ignored and ConditionallyIgnored attributes and comment tags act as markers, and they are the security control standing between a database column and a shipped bundle when you generate client-side code. Confirm the marker system is expressive enough for your actual sensitive-field inventory, including conditional cases. Combine markers with a review step because analysis output depends on environment state and can legitimately differ across local, CI, and staging.