Skip to content

Fix missing UnitEnum support in ModelNotFoundException - #59423

Merged
taylorotwell merged 2 commits into
laravel:12.xfrom
jtheuerkauf:fix-iss-55977-pr-59132-pr-59147
Mar 28, 2026
Merged

taylorotwell merged 2 commits into
laravel:12.xfrom
jtheuerkauf:fix-iss-55977-pr-59132-pr-59147

Conversation

@jtheuerkauf

Copy link
Copy Markdown
Contributor

Follow up to #55977 (PR #59132 and #59147)

This PR follows up on adding Enum support to the stringification of IDs passed to the exception. Initially only BackedEnum support was added. This switches to enum_value() to provide full support.

The original bug report points out this exception doesn't accept IDs the same way the rest of Builder logic does, particularly for enums. It's a non-breaking change and improves clean query building when dealing with non-stringable data.

isaackaara and others added 2 commits March 28, 2026 00:24
Extends the enum handling in setModel() to cover UnitEnum as well as
BackedEnum. The previous fix (using instanceof BackedEnum) missed
UnitEnum cases, which have no ->value but do have a ->name.

Using enum_value() — the framework helper — handles both cleanly:
- BackedEnum: returns ->value
- UnitEnum: returns ->name
- Everything else: passes through unchanged

Adds tests for both enum types.
* Adjusted previous fix, passing enum_value(...)
  instead of 'enum_value' to array_map() to fix test results

See: laravel#59147
@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jtheuerkauf
jtheuerkauf marked this pull request as ready for review March 28, 2026 19:14
@taylorotwell
taylorotwell merged commit c0dc1d5 into laravel:12.x Mar 28, 2026
72 checks passed
sumaiazaman added a commit to sumaiazaman/framework that referenced this pull request Mar 30, 2026
Forward-port fix from 12.x (laravel#59423). ModelNotFoundException used
instanceof BackedEnum which missed UnitEnum support. Replace with
enum_value() helper which handles both BackedEnum and UnitEnum.
jonagoldman pushed a commit to deplox/laravel-framework that referenced this pull request Apr 30, 2026
* fix: use enum_value() in ModelNotFoundException to support UnitEnum

Extends the enum handling in setModel() to cover UnitEnum as well as
BackedEnum. The previous fix (using instanceof BackedEnum) missed
UnitEnum cases, which have no ->value but do have a ->name.

Using enum_value() — the framework helper — handles both cleanly:
- BackedEnum: returns ->value
- UnitEnum: returns ->name
- Everything else: passes through unchanged

Adds tests for both enum types.

* Fix laravel#59147 - enum_value() should be a Closure

* Adjusted previous fix, passing enum_value(...)
  instead of 'enum_value' to array_map() to fix test results

See: laravel#59147

---------

Co-authored-by: Isaac Hunja <[email protected]>
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.

3 participants