Skip to content

[9.x] Adds support for PHP's BackedEnum to be "rendered" on blade views. - #44445

Merged
taylorotwell merged 5 commits into
9.xfrom
feat/e-enum-value
Oct 4, 2022
Merged

[9.x] Adds support for PHP's BackedEnum to be "rendered" on blade views.#44445
taylorotwell merged 5 commits into
9.xfrom
feat/e-enum-value

Conversation

@nunomaduro

Copy link
Copy Markdown
Member

This pull request is a very simple change that allows PHP's BackedEnum to be "rendered" on blade views.

enum UserRoles: string
{
    case ADMIN = 'Admin';
}

// routes/web.php
Route::get('/', function () {
    return view('dashboard', ['role' => UserRoles:: ADMIN]);
});

// dashboard.blade.php
Hello, {{ $role }}.

// ❌ Before: TypeError: htmlspecialchars(): Argument #1 ($string) must be of type string
// ✅ After: Hello, Admin.

Fixes #44431.

@nunomaduro nunomaduro self-assigned this Oct 4, 2022
@nunomaduro
nunomaduro marked this pull request as draft October 4, 2022 08:09
@nunomaduro
nunomaduro marked this pull request as ready for review October 4, 2022 08:17
@taylorotwell
taylorotwell merged commit fcdce7c into 9.x Oct 4, 2022
@taylorotwell
taylorotwell deleted the feat/e-enum-value branch October 4, 2022 13:32
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.

Crash when using Blade's echo to render enum

3 participants