- Does nilportugues/serializer-eloquent work with Laravel 10 and PHP 8.2+?
- No, the package hasn’t been updated since 2017 and lacks PHP 8.x compatibility. You’d need to patch named arguments, attributes, or strict typing manually or explore alternatives like Laravel’s built-in API resources or Fractal. Test thoroughly if attempting to use it with newer versions.
- How do I install and configure this package for Eloquent serialization?
- Run `composer require nilportugues/serializer-eloquent` and ensure `nilportugues/serializer` is installed. Configure the driver in your `config/serializer.php` (if applicable) and use `EloquentDriver::serialize($model)` to output normalized arrays for JSON, JSON:API, or HAL+JSON formats.
- Can this package handle complex Eloquent relationships like hasManyThrough or polymorphic models?
- The package supports basic relationships (one-to-one, one-to-many, has-many-through), but polymorphic and many-to-many relationships are listed as incomplete in the TODO section. Test these cases carefully, as they may not work as expected without additional customization.
- How does the performance compare to Laravel’s built-in API resources or Fractal?
- This package adds abstraction layers, so it may introduce slight overhead compared to native `toArray()` or Fractal. Benchmark against your current serialization method, especially for high-traffic APIs. For real-time systems, alternatives like Fractal or custom `toArray()` might be more performant.
- Is there a way to customize the serialized output (e.g., exclude fields, add metadata)?
- Yes, the package supports serializer drivers, normalizers, and filters for granular control. You can configure which fields to include/exclude, add custom attributes, or modify the output structure via the underlying `nilportugues/serializer` library’s configuration.
- Will this package work with non-Eloquent models or collections (e.g., DTOs, arrays)?
- Primarily designed for Eloquent models, but you could extend the driver to support other objects by implementing custom normalizers. For collections or DTOs, consider using the base `nilportugues/serializer` library directly or pairing it with Fractal for broader compatibility.
- Are there any known issues with circular references or deeply nested models?
- The package may not handle circular references or deeply nested models out of the box. You’ll need to implement custom logic (e.g., recursion limits or cycle detection) in your normalizers or filters. Test edge cases thoroughly, especially with complex relationships.
- What’s the maintenance status, and is the author responsive to issues?
- The package is unmaintained since 2017, with no recent commits or releases. The author may not respond to issues promptly. For critical projects, consider forks like `spatie/array-to-xml` or alternatives (e.g., Fractal) with active development.
- Can I use this for JSON:API or HAL+JSON formats in Laravel 9+?
- Yes, the package supports JSON:API and HAL+JSON formats, but compatibility with Laravel 9+ isn’t guaranteed due to PHP 8.x syntax changes. You may need to override or patch the driver to work with newer Laravel versions. Test thoroughly against your API contract requirements.
- What are the alternatives if this package doesn’t meet my needs?
- Consider Laravel’s built-in [API Resources](https://laravel.com/docs/10.x/eloquent-resources) for modern Laravel apps, [Fractal](https://fractal.thephpleague.com/) for flexible serialization, or [Spatie’s packages](https://spatie.be/docs/laravel-serialization) for simpler use cases. These alternatives are actively maintained and support Laravel 10+.