Repository navigation
Conversation
dshafik
force-pushed
the
lazily-resolve-route-model-binding
branch
2 times, most recently
from
January 1, 2025 12:24
cd86130 to
8a7b787
Compare
dshafik
force-pushed
the
lazily-resolve-route-model-binding
branch
3 times, most recently
from
January 2, 2025 03:09
8c198e8 to
919ae88
Compare
dshafik
force-pushed
the
lazily-resolve-route-model-binding
branch
from
January 2, 2025 04:01
919ae88 to
61e6686
Compare
Member
|
If this can be handled in user land I would much rather it be handled there via a package. 🫶 |
Contributor
Author
Insofar as this works, yes. If you wanted to solve the scoped bindings are all deferred, then no, it requires a change in how relationships are created. I didn't want to do that work without feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into the behavior that was reported in #44177 and am proposing this addition to help resolve it by deferring the query until the model is used.
To be clear: this changes no existing behavior. There is a single thing I couldn't resolve with this, which is that when using scoped bindings only the final child model will end up being deferred. I don't think this is a big deal, but it would be great if the entire chain could be deferred — the problem is there's no way to get the relationship to figure out the child model without it pulling the
idof the parent and that implicitly resolves the parent.This probably should just be a package, but I wanted to see if there was interest in including it in the core framework first.
Here's a draft attempt at docs to explain it:
Deferred Binding
By default, models are resolved before route middleware has been executed, this means that any global scopes applied to the model that rely on data created in middleware will not function as expected.
To resolve this, you can use the
DeferRouteBindingtrait. When used in your models, the query is deferred when binding until either explicitly or implicitly loaded within the method itself:You should ensure to load the model prior to executing any other code that would later fail if the model is not found.
Note: when using scoped bindings, only the final "child" model will be deferred.