- What Laravel versions does Laravel Ranger support?
- Laravel Ranger is designed for Laravel 10+ and requires PHP 8.1+. It leverages Laravel’s service container and modern features, so older versions (e.g., Laravel 9 or below) are not supported. Always check the package’s changelog for updates on compatibility.
- How do I install and set up Laravel Ranger in my project?
- Install via Composer with `composer require laravel/ranger`. Register the service provider in `config/app.php` under `providers`, then use the `Ranger` facade or resolve it via the container. Start by defining callbacks for components like routes or models before running `walk()` to trigger introspection.
- Can I use Laravel Ranger to generate API documentation automatically?
- Yes, Ranger’s DTOs include rich metadata like URIs, handlers, and model attributes, making it ideal for generating API docs. Register a callback for routes or models, then serialize the DTOs to JSON or Markdown. Tools like Swagger or custom scripts can consume this data for documentation.
- What happens if I register a callback but no components match (e.g., no enums in my app)?
- Callbacks are only triggered when matching components are discovered. If no enums exist, the `onEnum` callback won’t fire, but other callbacks (e.g., routes or models) will execute as expected. This design ensures efficiency by skipping irrelevant components.
- Is Laravel Ranger safe to run in production? Will it impact performance?
- Ranger is safe for production but can be CPU-intensive during introspection. Test with production-like data volumes to measure runtime impact. For large apps, offload scans to queues (e.g., Laravel Horizon) or run them during low-traffic periods. Avoid real-time introspection during peak usage.
- How do I handle sensitive data like API keys in environment variables when using Ranger?
- Ranger collects environment variables, but you must manually redact sensitive data (e.g., API keys) before processing or exporting DTOs. Use callback logic to filter or mask values, or pre-process `.env` files to remove sensitive entries before introspection.
- Can I use Laravel Ranger to detect deprecated or unused routes/models?
- Indirectly, yes. Ranger provides metadata like route URIs and model attributes, which you can cross-reference with usage logs (e.g., Laravel’s request logging) or analytics tools. Combine Ranger’s output with external data to identify deprecated or unused components.
- What alternatives exist to Laravel Ranger for codebase introspection?
- Alternatives include custom scripts using Laravel’s reflection tools, IDE plugins (e.g., PHPStorm’s structural search), or packages like `spatie/laravel-activitylog` for event-based tracking. However, Ranger uniquely combines route, model, enum, and Inertia.js discovery in a single, callback-driven library.
- How do I test Laravel Ranger in my CI/CD pipeline?
- Add Ranger to your CI pipeline by running `php artisan ranger:scan` (if available) or a custom script that triggers `walk()`. Validate outputs against expected schemas (e.g., JSON Schema) and mock callbacks to ensure stability. Test edge cases like empty collections or custom component types.
- Will Laravel Ranger work with custom route/middleware configurations or non-standard model setups?
- Ranger should handle most custom configurations, but test thoroughly with your specific setup. Complex middleware chains or dynamic route generation might require custom collectors or callback logic. Check the package’s issue tracker for reported edge cases or limitations.