Skip to content

[12.x] Support Virtual Properties When Serializing Models #55691

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

Merged

Conversation

beschoenen
Copy link
Contributor

When serializing models using the SerializesModels trait that contain PHP 8.4's new property hooks. The serializing fails with the following error:

namespace MyNamespace;

class MyClass
{
  use SerializesModels;

  public string $property {
    get {
      return 'Foo';
    }
  }
}
Property MyNamespace\MyClass::$property is read-only

These new property that do not actually contain any value, are virtual and can be safely ignored during serialization.

I'm not a 100% sure on how to test this code since it's only applicable to PHP 8.4.

@taylorotwell taylorotwell merged commit 98043a8 into laravel:12.x May 9, 2025
40 of 60 checks passed
@beschoenen beschoenen deleted the feature/support-virtual-properties branch May 9, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants