RFC: Native Object Cast for JSON Columns (AsJsonObject) #58425
Replies: 1 comment
-
|
Ehm, this is not true. You can use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Author: Amadul
Related Package: amadul/json-object
Target: Laravel Eloquent ORM
Status: Proposal / RFC
1. Problem Statement
Laravel currently provides the following JSON casts:
arraycollectionAsCollectionAsEncryptedArrayObjectAsEncryptedCollectionThese casts treat JSON as data containers, not domain objects.
Current limitation
There is no native way to treat JSON columns as object graphs with:
->)2. Real-World Use Cases (Why This Matters)
JSON columns are increasingly used for:
In these cases:
Laravel lacks a first-class JSON object abstraction.
3. Proposed Solution
Introduce a new native cast:
Example Usage
Developer Experience
4. Expected Behavior
Reading
->)Writing
5. Minimal Core Feature Set (Laravel-Friendly)
Laravel prefers small, composable features.
Core responsibilities only:
❌ No validation
❌ No schema enforcement
❌ No DTO logic
(Advanced features remain package-level)
6. Example Core Implementation (Conceptual)
7. Why This Belongs in Laravel Core
Fits Laravel Philosophy
Aligns With Existing Casts
AsCollectionAsArrayObjectAsJsonObjectThis is a natural evolution, not a breaking change.
8. Backward Compatibility
9. Community Validation
The feature is already validated by real usage via:
amadul/json-objectLaravel has historically adopted ideas from:
10. Alternative Considered (Why Not Enough)
11. Proposed Naming Options
Laravel-style naming suggestions:
AsObjectAsJsonObject✅ (clear & explicit)AsDataObject12. Migration Path (Optional)
No refactor required in business logic.
Beta Was this translation helpful? Give feedback.
All reactions