Skip to content

Conversation

@hosni
Copy link
Contributor

@hosni hosni commented Dec 8, 2025

This PR adds support for using PHP Enums as values in the translator’s replacement array.

Right now, if an Enum is passed to the replaces array, the translator tries to treat the Enum object as a string. That causes a TypeError when mb_substr() is called. For example:

{
    "class": "TypeError",
    "message": "mb_substr(): Argument #1 ($string) must be of type string, App\\Enums\\UserStatus given",
    "file": "/vendor/laravel/framework/src/Illuminate/Support/Str.php:1718"
}

Because of:

$shouldReplace[':'.Str::ucfirst($key)] = Str::ucfirst($value ?? '');
$shouldReplace[':'.Str::upper($key)] = Str::upper($value ?? '');

The change updates Translator::makeReplacements() so that Enum values are converted to their underlying value before the replacement logic runs. This brings Enum handling in line with how other simple value types are treated.

Tests are included for string-backed, int-backed, and unit Enums.

No breaking changes.

@hosni hosni force-pushed the support-enum-in-translator branch from 4e366a0 to 604ae57 Compare December 8, 2025 13:57
@taylorotwell taylorotwell merged commit ef5aa3d into laravel:12.x Dec 8, 2025
74 checks passed
@hosni hosni deleted the support-enum-in-translator branch December 16, 2025 08:09
@hosni hosni restored the support-enum-in-translator branch December 16, 2025 08:09
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