Upgrade to Laravel 12 and PHP 8.5, remove deprecated registerData #35
+2,706
−1,406
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Major Version Upgrade
This PR upgrades the package to Laravel 12 and PHP 8.5, and removes the deprecated
registerDatafunctionality.1. Minimum Requirements
2. Removed Deprecated Functionality
register()methodregisterDataproperty3. Method Visibility Change
toAttributes()is now public (was protected) for Laravel 12 compatibility📝 Changes Made
Dependencies Updated
^8.2→^8.5^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0→^12.0^7.22.0→^10.0^9.6.3→^11.0Laravel 12 Compatibility Fixes
resolveResourceData()override to prevent circular dependency betweentoArray()andtoAttributes()toAttributes()visibility fromprotectedtopublicto match Laravel 12's baseJsonResourceclasstoAttributes()and how it differs from Laravel's implementationRemoved Deprecated Code
private array $registerDatapropertyprotected function register(): arraymethodregisterDataingetType(),toAttributes(),toRelationships(),toMeta(),toLinks()Test Resources Converted
All test resources converted from
register()to method-based approach:AccountResource.phpPostResource.phpCommentResource.php🧪 Testing
All tests passing:
📖 Migration Guide for Users
Step 1: Update Requirements
Step 2: Change Method Visibility
Change all
protected function toAttributes()topublic function toAttributes():Step 3: Convert register() to Method-Based Definitions
Before (deprecated):
After (required):
🔍 Technical Details
Why Override
toAttributes()?Laravel 12's
toAttributes()returns the full resource (same astoArray()), but JSON:API needs it to return only the attributes portion:Laravel's behavior:
JSON:API behavior:
This override is intentional and necessary to:
📌 Notes