Skip to content

[13.x] Fix AsHtmlString attributes serializing to an empty object - #61854

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:as-html-string-serialization
Oct 5, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
xurshudyan:as-html-string-serialization

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

Attributes cast with AsHtmlString come out as {} in toArray() / toJson(), because HtmlString isn't JsonSerializable.

protected $casts = ['bio' => AsHtmlString::class];

$user->toJson(); // {"bio":{}}

AsUri had the same problem in #56094. Adding JsonSerializable to HtmlString was turned down in #20247, so this fixes it in the cast instead.

@taylorotwell
taylorotwell merged commit bbcc9fe into laravel:13.x Oct 5, 2026
62 checks passed
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 26, 2026
Apply laravel/framework#61854 (bbcc9fec48). AsHtmlString implements the cast serialization contract, preserving string content in model arrays and JSON instead of exposing an HtmlString object. Null remains null. The complete upstream regression reproduced the old result; custom-cast integration tests, formatting and full analysis pass.
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