You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created pull request#20384 to fix tap method problem, but maybe Taylor didn't understand what is the problem exactly. So i decided to create an issue and describe it here.
The main problem is tap method passes Illuminate\Database\Query\Builder to the callback, so it's impossible to use Eloquent Builder features in the callback (like relations, scopes).
But when method works correctly. It's uses Illuminate\Database\Eloquent\Builder as argument for the callback.
Based on this we have a new issue - we can't use one type hint callback for the tap and when methods.
Steps To Reproduce:
Model::tap(function ($builder) {
/* * This will throw an exception * BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::with()' */$builer->with('relation');
});
// We can't use typehint for $builder argument$callback = function ($builder) {
echoget_class($builder);
};
Model::where('condition', 'value')
->when(true, $callback) // Illuminate\Database\Eloquent\Builder
->tap($callback); // Illuminate\Database\Query\Builder
The text was updated successfully, but these errors were encountered:
Description:
I created pull request#20384 to fix
tap
method problem, but maybe Taylor didn't understand what is the problem exactly. So i decided to create an issue and describe it here.The main problem is
tap
method passesIlluminate\Database\Query\Builder
to the callback, so it's impossible to use Eloquent Builder features in the callback (like relations, scopes).But
when
method works correctly. It's usesIlluminate\Database\Eloquent\Builder
as argument for the callback.Based on this we have a new issue - we can't use one type hint callback for the
tap
andwhen
methods.Steps To Reproduce:
The text was updated successfully, but these errors were encountered: