Skip to content

Conversation

@adhikjoshi
Copy link

Currently only one Eloquent Casts is added AsDataObject

Adding remaining casts to make hypervel drop-in-replacement of Laravel

ArrayObject
AsArrayObject
AsCollection
Attribute
Json
AsStringable

https://github.com/laravel/framework/blob/12.x/src/Illuminate/Database/Eloquent/Casts/Attribute.php

@adhikjoshi
Copy link
Author

@albertcht Can you look into this?

@albertcht
Copy link
Member

Hi @adhikjoshi, thanks for your pull request! I will look into this PR by this weekend.

@albertcht albertcht added the feature New feature or request label Nov 7, 2025
@albertcht albertcht requested a review from Copilot November 7, 2025 17:57
Copy link

Copilot AI left a 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 Castable interface to support CastsAttributes as a return type
  • Adds JSON encoding/decoding utility class with customizable encoders/decoders
  • Introduces new cast classes for collections and array objects
  • Adds Attribute class 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
Copy link

Copilot AI Nov 7, 2025

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.

Suggested change
* @var callable
* @var callable|null

Copilot uses AI. Check for mistakes.
/**
* The attribute mutator.
*
* @var callable
Copy link

Copilot AI Nov 7, 2025

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.

Suggested change
* @var callable
* @var callable|null

Copilot uses AI. Check for mistakes.
* 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;
Copy link

Copilot AI Nov 7, 2025

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.

Copilot uses AI. Check for mistakes.
protected static $encoder;

/**
* The custom JSON decode.
Copy link

Copilot AI Nov 7, 2025

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.

Suggested change
* The custom JSON decode.
* The custom JSON decoder.

Copilot uses AI. Check for mistakes.
* 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>
Copy link

Copilot AI Nov 7, 2025

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).

Suggested change
* @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, mixed>, iterable>
* @return \Hyperf\Contract\CastsAttributes<\Hypervel\Support\Collection<array-key, mixed>, iterable>

Copilot uses AI. Check for mistakes.
* 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>
Copy link

Copilot AI Nov 7, 2025

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).

Suggested change
* @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed>, iterable>
* @return \Hyperf\Contract\CastsAttributes<\ArrayObject<array-key, mixed>, iterable>

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants