This release significantly enhances the usability of the Presenter package:
- Automatic array and JSON conversion: Presenters can now be directly passed to views or returned from routes without explicitly calling
toArray()
ortoJson()
. - Array access support: Presenters implement
ArrayAccess
, allowing them to be used like arrays. - JSON serialization: Presenters now implement
JsonSerializable
for seamless JSON encoding. - Abstract
toArray()
method: Enforces proper implementation in child classes, ensuring consistent behavior. - Updated documentation: README now clearly explains the new automatic conversion features and provides usage examples.
- Expanded test coverage: New tests added for array access and JSON serialization functionality.
These improvements streamline the use of Presenters in Laravel applications, particularly for view data preparation and API responses, reducing boilerplate code and potential errors.
Important Note for Existing Users: If you're currently calling toArray()
explicitly when using Presenters (e.g., UserPresenter::make($user)->toArray()
), please note that these calls will continue to work as before. However, they are no longer necessary in most contexts due to the new automatic conversion feature. You can safely remove these explicit calls if desired, which will make your code cleaner and more concise.
These changes maintain backward compatibility while offering new, more convenient ways to use Presenters in your Laravel applications.