Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add parameter typing for closure to addGlobalScope method #54677

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Concerns/HasGlobalScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static function resolveGlobalScopeAttributes()
/**
* Register a new global scope on the model.
*
* @param \Illuminate\Database\Eloquent\Scope|\Closure|string $scope
* @param \Illuminate\Database\Eloquent\Scope|\Closure|null $implementation
* @param \Illuminate\Database\Eloquent\Scope|(\Closure(\Illuminate\Database\Eloquent\Builder<static>): mixed)|string $scope
* @param \Illuminate\Database\Eloquent\Scope|(\Closure(\Illuminate\Database\Eloquent\Builder<static>): mixed)|null $implementation
* @return mixed
*
* @throws \InvalidArgumentException
Expand Down Expand Up @@ -93,7 +93,7 @@ public static function hasGlobalScope($scope)
* Get a global scope registered with the model.
*
* @param \Illuminate\Database\Eloquent\Scope|string $scope
* @return \Illuminate\Database\Eloquent\Scope|\Closure|null
* @return \Illuminate\Database\Eloquent\Scope|(\Closure(\Illuminate\Database\Eloquent\Builder<static>): mixed)|null
*/
public static function getGlobalScope($scope)
{
Expand Down
6 changes: 6 additions & 0 deletions types/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function test(User $user, Post $post, Comment $comment, Article $article): void
return ['string' => 'string'];
}));

User::addGlobalScope('ancient', function ($builder) {
assertType('Illuminate\Database\Eloquent\Builder<User>', $builder);

$builder->where('created_at', '<', now()->subYears(2000));
});

assertType('Illuminate\Database\Eloquent\Builder<User>', User::query());
assertType('Illuminate\Database\Eloquent\Builder<User>', $user->newQuery());
assertType('Illuminate\Database\Eloquent\Builder<User>', $user->withTrashed());
Expand Down
Loading