Skip to content

Commit d8ecb1d

Browse files
authored
Type the callback for Relation::noConstraints (#54572)
1 parent f7a68a7 commit d8ecb1d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Illuminate/Database/Eloquent/Relations/Relation.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ public function __construct(Builder $query, Model $parent)
102102
/**
103103
* Run a callback with constraints disabled on the relation.
104104
*
105-
* @param \Closure $callback
106-
* @return mixed
105+
* @template TReturn of mixed
106+
*
107+
* @param Closure(): TReturn $callback
108+
* @return TReturn
107109
*/
108110
public static function noConstraints(Closure $callback)
109111
{

types/Database/Eloquent/Relations.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Illuminate\Database\Eloquent\Relations\MorphOne;
1414
use Illuminate\Database\Eloquent\Relations\MorphTo;
1515
use Illuminate\Database\Eloquent\Relations\MorphToMany;
16+
use Illuminate\Database\Eloquent\Relations\Relation;
1617

1718
use function PHPStan\Testing\assertType;
1819

@@ -123,6 +124,8 @@ function test(User $user, Post $post, Comment $comment, ChildUser $child): void
123124

124125
assertType('Illuminate\Database\Eloquent\Relations\MorphToMany<Illuminate\Types\Relations\Tag, Illuminate\Types\Relations\Post>', $post->tags());
125126
assertType('Illuminate\Database\Eloquent\Collection<int, Illuminate\Types\Relations\Tag>', $post->tags()->getResults());
127+
128+
assertType('42', Relation::noConstraints(fn () => 42));
126129
}
127130

128131
class User extends Model

0 commit comments

Comments
 (0)