- How does Orion reduce boilerplate for REST API endpoints in Laravel?
- Orion provides pre-built controller structures, CRUD operations, and common API features like filtering, sorting, and pagination. Instead of writing repetitive code for each Eloquent model, you define rules once and let Orion generate the endpoints automatically, cutting development time significantly.
- Which Laravel versions does Orion support?
- Orion is designed for Laravel 8.x and 9.x, leveraging modern PHP features like named arguments and attributes. Check the package’s `composer.json` for exact version constraints, but it avoids breaking changes with Laravel’s core API patterns.
- Can Orion handle complex API filtering (e.g., nested relations or custom logic)?
- Yes, Orion supports dynamic filtering via query builder methods or Eloquent scopes. For nested relations, you can define them in the model’s `$with` property or use Orion’s relation handling to include them in responses automatically. Custom logic can be injected via closures or middleware.
- Does Orion work with Laravel’s built-in API resources or does it require its own?
- Orion integrates seamlessly with Laravel’s API resources. You can use existing resources or define new ones, and Orion will handle serialization, pagination, and metadata (like links for pagination) automatically. This keeps your API responses consistent with Laravel’s conventions.
- How does Orion handle API authorization (e.g., Gates, Policies, or middleware)?
- Orion supports Laravel’s native authorization mechanisms, including Gates, Policies, and middleware. You can attach authorization logic to specific actions (e.g., `index`, `store`) via the package’s configuration or by extending Orion’s base controller. It won’t override your existing auth setup.
- Is Orion compatible with Laravel’s Sanctum or Passport for API authentication?
- Absolutely. Orion treats authentication as a first-class citizen and works out of the box with Sanctum, Passport, or any other Laravel auth package. You just need to ensure your routes are protected with the usual middleware (e.g., `auth:sanctum`), and Orion will respect those rules.
- Can I customize Orion’s pagination (e.g., custom page sizes, cursor-based pagination)?
- Yes, Orion allows full customization of pagination. You can override default settings like items per page, use cursor-based pagination with `CursorPaginator`, or even disable pagination entirely for specific endpoints. Configuration is done via the package’s service provider or model bindings.
- Does Orion support API versioning, and how does it handle route conflicts?
- Orion integrates with Laravel’s route model binding and API versioning (e.g., via `Route::prefix('v1')`). To avoid conflicts, it uses namespaced controllers and allows you to define version-specific configurations. You can also manually prefix routes or use Laravel’s built-in versioning tools.
- How do I test Orion’s API endpoints in PHPUnit or Pest?
- Testing Orion endpoints is straightforward with Laravel’s testing tools. Use `Http::fake()` to mock API responses, test authorization with `actingAs()`, and validate JSON responses with `assertJson()`. Orion’s controllers follow Laravel conventions, so existing test patterns (e.g., `create()`, `assertDatabaseHas()`) work seamlessly.
- Are there performance considerations when using Orion in production?
- Orion is optimized for performance, but heavy use of dynamic filtering or deep relations may impact query complexity. Always profile your API with tools like Laravel Debugbar or Blackfire. For large datasets, consider caching responses or using database indexes for filtered queries. Orion’s pagination and eager loading help mitigate overhead.