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.
An attempt to document the feature added in laravel/framework#53720. I wrote everything that felt like it might be useful. And tried to put it in places where a reader might look exactly when this could be useful for them. Some of my reasoning below.
The initial description of
withAttributes
is in the scopes' section ofeloquent.md
because IMO that's where the simplest use of this feature makes sense.The feature feels most useful inside relationships so I mentioned it in that doc as well. But I added a broader section introducing the various options of "scoping" relationships. I suspect this might be useful as I've seen many new devs viewing the relationship methods as some special syntax that may only include the
$this->relationshipMethod(RelatedModel::class);
and nothing else.I added that section at the end of the first batch of relationship methods as that's where the reader seems familiar enough with relationships themselves. In the next section (many to many) I added a note about
withPivotValue
while referring to the same concept of being "scoped" that was introduced earlier....or maybe these are constrained relationships, not scoped ones?