-
-
Notifications
You must be signed in to change notification settings - Fork 13
Adding remaining Eloquent Casts #266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@albertcht Can you look into this? |
|
Hi @adhikjoshi, thanks for your pull request! I will look into this PR by this weekend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds database model casting support by introducing new casting classes and updating the Castable interface to support additional return types. The changes extend the framework's ability to handle JSON data and create custom attribute accessors/mutators for Eloquent models.
- Extends the
Castableinterface to supportCastsAttributesas a return type - Adds JSON encoding/decoding utility class with customizable encoders/decoders
- Introduces new cast classes for collections and array objects
- Adds
Attributeclass for defining custom accessors and mutators
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/foundation/src/Http/Contracts/Castable.php | Updates interface to support CastsAttributes return type from Hyperf contract |
| src/core/src/Database/Eloquent/Casts/Json.php | Adds JSON utility class with customizable encoding/decoding support |
| src/core/src/Database/Eloquent/Casts/Attribute.php | Introduces attribute accessor/mutator class with caching support |
| src/core/src/Database/Eloquent/Casts/AsCollection.php | Implements castable for collection types with optional mapping |
| src/core/src/Database/Eloquent/Casts/AsArrayObject.php | Implements castable for ArrayObject with JSON serialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * The attribute accessor. | ||
| * | ||
| * @var callable |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @var annotation for the $get property should be callable|null since it can be null as shown in the constructor signature and the set() method implementation.
| * @var callable | |
| * @var callable|null |
| /** | ||
| * The attribute mutator. | ||
| * | ||
| * @var callable |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @var annotation for the $set property should be callable|null since it can be null as shown in the constructor signature and the get() method implementation.
| * @var callable | |
| * @var callable|null |
| * Get the name of the caster class to use when casting from / to this cast target. | ||
| */ | ||
| public static function castUsing(array $arguments = []): CastInputs|string; | ||
| public static function castUsing(array $arguments = []): CastInputs|CastsAttributes|string; |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CastInputs interface is referenced in the return type but not imported. Add use Hypervel\Foundation\Http\Contracts\CastInputs; at the top of the file to properly resolve this type.
| protected static $encoder; | ||
|
|
||
| /** | ||
| * The custom JSON decode. |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docblock comment says "The custom JSON decode" but should say "The custom JSON decoder" to maintain grammatical consistency with "encoder" on line 10.
| * The custom JSON decode. | |
| * The custom JSON decoder. |
| * Get the caster class to use when casting from / to this cast target. | ||
| * | ||
| * @param array $arguments | ||
| * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, mixed>, iterable> |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docblock references \Illuminate\Contracts\Database\Eloquent\CastsAttributes and \Illuminate\Support\Collection but this codebase uses the Hypervel and Hyperf namespaces. The return type annotation should reference the correct namespace (e.g., \Hyperf\Contract\CastsAttributes and \Hypervel\Support\Collection).
| * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, mixed>, iterable> | |
| * @return \Hyperf\Contract\CastsAttributes<\Hypervel\Support\Collection<array-key, mixed>, iterable> |
| * Get the caster class to use when casting from / to this cast target. | ||
| * | ||
| * @param array $arguments | ||
| * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed>, iterable> |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docblock references \Illuminate\Contracts\Database\Eloquent\CastsAttributes and \Illuminate\Database\Eloquent\Casts\ArrayObject but this codebase uses the Hypervel and Hyperf namespaces. The return type annotation should reference the correct namespace (e.g., \Hyperf\Contract\CastsAttributes).
| * @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed>, iterable> | |
| * @return \Hyperf\Contract\CastsAttributes<\ArrayObject<array-key, mixed>, iterable> |
Currently only one Eloquent Casts is added
AsDataObjectAdding remaining casts to make hypervel drop-in-replacement of Laravel
ArrayObjectAsArrayObjectAsCollectionAttributeJsonAsStringablehttps://github.com/laravel/framework/blob/12.x/src/Illuminate/Database/Eloquent/Casts/Attribute.php