[8.x] Add forwardDecoratedCallTo #38800
Merged
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.
This PR adds an additional method to
ForwardsCalls
to allow for easy fluent calls to decorated objects. This pattern is used in theRelation
class as well as in theDecoratesQueryBuilder
trait that will be introduced in Laravel 9. Under the hood, this essentially performs:This is a nice solution, because we continue to receive our proxy object until we make a call that isn't fluent on the underlying decorated object.
There are a handful of places that could be updated to use this new method. Because these are mild breaking changes, I'll introduce them in 9.x PR should this PR get merged. These are:
Illuminate\Events\NullDispatcher
Illuminate\Http\Resources\DelegatesToResource
Illuminate\Mail\Message
Illuminate\Pagination\AbstractPaginator
andAbstractCursorPaginator
In each of these cases, I believe the expected behavior of any delegated fluent call would be to receive the proxy object, whereas right now you would receive the underlying object.
For example, in the case of
Illuminate\Mail\Message
: