- Can I use API Platform Core directly in Laravel without Symfony, or is it strictly for Symfony projects?
- API Platform Core is primarily designed for Symfony, but it can be integrated into Laravel via the `api-platform/laravel` bundle. While the core library itself doesn’t require Symfony, Laravel-specific optimizations (like Eloquent integration) rely on the bundle. Ensure your Laravel project can handle Symfony 7.4+ dependencies, as Core now requires it.
- What Laravel versions are officially supported by API Platform Core?
- API Platform Core itself doesn’t enforce Laravel version constraints, but compatibility depends on the `api-platform/laravel` bundle and Symfony 7.4/8.0 requirements. Laravel 9.x+ projects should work, but test thoroughly—especially if using older Symfony components (e.g., PropertyAccess). Check the bundle’s docs for exact Laravel version support.
- How do I migrate from JSON:API status as an object to the new string format?
- Update client integrations to handle the `status` field as a string instead of an object. Use the `@ApiProperty` annotation or DTOs to enforce the new format. Validate API responses with tools like Postman or custom scripts to ensure backward compatibility. The change aligns with JSON:API spec updates but may break existing clients.
- Are there performance best practices for API Platform Core in Laravel production?
- Leverage standalone filters (e.g., `DateFilter`, `ComparisonFilter`) to optimize queries and reduce N+1 issues. Enable caching for Hydra contexts or API responses using Redis or OPcache. Profile with Blackfire to identify bottlenecks, especially in GraphQL-REST hybrid setups. Avoid eager-loading unnecessary collections in DTOs.
- How do I handle custom serializers or filters if API Platform Core deprecates legacy APIs?
- Audit your custom serializers for `PropertyInfo` Type system usage and migrate to `symfony/type-info`. For filters, replace deprecated logic with new standalone filters (e.g., `ExistsFilter`). Use the `StateProvider` interface for complex workflows. Test thoroughly—deprecated APIs may throw warnings or errors in Symfony 7.4+.
- Can I mix REST and GraphQL in the same API Platform Core project?
- Yes, but schema alignment may require manual effort. Use shared DTOs or custom resolvers to sync data between REST (Hydra/JSON-LD) and GraphQL schemas. Validate with Symfony’s new APIs for schema stitching. GraphQL queries can fetch REST resources via `@ApiResource` annotations, but complex relationships may need resolver overrides.
- What are the risks of using Symfony 7.4/8.0 dependencies in a Laravel project?
- Symfony 7.4+ may conflict with older Laravel Symfony components (e.g., `PropertyAccess`). Use Composer’s `platform-check` or override services in Laravel’s `config/app.php` to resolve conflicts. Test thoroughly for breaking changes, especially in authentication (e.g., OAuth2) or caching layers. The `api-platform/laravel` bundle mitigates some risks but isn’t a full compatibility layer.
- How do I add UUID-based filtering to API Platform Core in Laravel?
- Use the `UuidFilter` from the `api-platform/laravel` bundle. Register it in your `config/api_platform/resources.yaml` under the resource’s `filters` section. For custom UUID fields, extend the filter or use a `ComparisonFilter` with the `uuid` operator. Ensure your Eloquent model uses Laravel’s `HasUuid` trait or a compatible UUID column type.
- Are there alternatives to API Platform Core for Laravel GraphQL APIs?
- For GraphQL, consider `graphql-php/graphql-php` (standalone) or `rebing/graphql-laravel` (Laravel-specific). For REST, alternatives include `spatie/laravel-api-resources` (simpler) or `filp/whoops` for error handling. API Platform Core stands out for hypermedia (HATEOAS) and multi-format support (JSON-LD, Hydra), but may be overkill for lightweight APIs.
- How do I test API Platform Core in Laravel for production readiness?
- Use Pest or PHPUnit to test API responses, filters, and GraphQL queries. Validate Hydra contexts with tools like `hydra-validator`. Load-test with tools like k6 to check performance under traffic. Test edge cases like pagination, authentication (e.g., OAuth2), and error responses (RFC7807). Mock external services if your API depends on them.