Proposal: Fail on unresolved route model bindings instead of returning blank model #56197
Unanswered
kieranbarlow
asked this question in
Ideas
Replies: 1 comment
-
This seems more like a bug than like a new feature. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In Laravel, when a route uses model binding like:
Route::get('/companies/{company:uuid}', fn (Company $company) => ...);
If the route parameter is misspelled (e.g. {commpany:uuid}) or the binding fails, Laravel does not throw an error. Instead, it silently resolves the model using new Company(), resulting in a blank instance.
This can lead to odd behavior:
• Controllers receive an empty model without realising the binding failed
• Developers unintentionally call update(), delete() or other mutating methods on a phantom model
• No errors or exceptions are thrown, making the bug very hard to trace
Should we introduce a way to fail fast when route model binding fails, instead of silently falling back to an empty model instance.
Is this worth formalising into a PR, or should we just treat it as something developers should manually guard against?
Beta Was this translation helpful? Give feedback.
All reactions