diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 3a614e88d161..507177fddd69 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1537,8 +1537,10 @@ protected function createNestedWhere($whereSlice, $boolean = 'and') /** * Set the relationships that should be eager loaded. * - * @param array): mixed)|string>|string $relations - * @param (\Closure(\Illuminate\Database\Eloquent\Relations\Relation<*,*,*>): mixed)|string|null $callback + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations + * @param (\Closure(TRelation): mixed)|string|null $callback * @return $this */ public function with($relations, $callback = null) @@ -1572,7 +1574,9 @@ public function without($relations) /** * Set the relationships that should be eager loaded while removing any previously added eager loading specifications. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @return $this */ public function withOnly($relations) diff --git a/src/Illuminate/Database/Eloquent/Collection.php b/src/Illuminate/Database/Eloquent/Collection.php index 62e84780a7d6..987ec84459b1 100755 --- a/src/Illuminate/Database/Eloquent/Collection.php +++ b/src/Illuminate/Database/Eloquent/Collection.php @@ -84,7 +84,9 @@ public function findOrFail($key) /** * Load a set of relationships onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @return $this */ public function load($relations) @@ -105,7 +107,9 @@ public function load($relations) /** * Load a set of aggregations over relationship's column onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @param string $column * @param string|null $function * @return $this @@ -142,7 +146,9 @@ public function loadAggregate($relations, $column, $function = null) /** * Load a set of relationship counts onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @return $this */ public function loadCount($relations) @@ -153,7 +159,9 @@ public function loadCount($relations) /** * Load a set of relationship's max column values onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @param string $column * @return $this */ @@ -165,7 +173,9 @@ public function loadMax($relations, $column) /** * Load a set of relationship's min column values onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @param string $column * @return $this */ @@ -177,7 +187,9 @@ public function loadMin($relations, $column) /** * Load a set of relationship's column summations onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @param string $column * @return $this */ @@ -189,7 +201,9 @@ public function loadSum($relations, $column) /** * Load a set of relationship's average column values onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @param string $column * @return $this */ @@ -201,7 +215,9 @@ public function loadAvg($relations, $column) /** * Load a set of related existences onto the collection. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @return $this */ public function loadExists($relations) @@ -212,7 +228,9 @@ public function loadExists($relations) /** * Load a set of relationships onto the collection if they are not already eager loaded. * - * @param array): mixed)|string>|string $relations + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * + * @param array|string $relations * @return $this */ public function loadMissing($relations) @@ -283,8 +301,10 @@ protected function loadMissingRelation(self $models, array $path) /** * Load a set of relationships onto the mixed relationship collection. * + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * * @param string $relation - * @param array): mixed)|string> $relations + * @param array $relations * @return $this */ public function loadMorph($relation, $relations) @@ -300,8 +320,10 @@ public function loadMorph($relation, $relations) /** * Load a set of relationship counts onto the mixed relationship collection. * + * @template-covariant TRelation of \Illuminate\Database\Eloquent\Relations\Relation + * * @param string $relation - * @param array): mixed)|string> $relations + * @param array $relations * @return $this */ public function loadMorphCount($relation, $relations) diff --git a/types/Database/Eloquent/Builder.php b/types/Database/Eloquent/Builder.php index ba46642414eb..00be380df896 100644 --- a/types/Database/Eloquent/Builder.php +++ b/types/Database/Eloquent/Builder.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\HasBuilder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Query\Builder as QueryBuilder; use User; @@ -25,14 +26,23 @@ function test( assertType('Illuminate\Database\Eloquent\Builder', $query->whereNot('status', 'active')); assertType('Illuminate\Database\Eloquent\Builder', $query->with('relation')); assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => ['foo' => fn ($q) => $q]])); - assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); + assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => function (HasMany $query): void { + assertType('Illuminate\Database\Eloquent\Relations\HasMany', $query); + }])); + assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => function (HasOne $query): void { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); + }])); + assertType('Illuminate\Database\Eloquent\Builder', $query->with(['relation' => function (MorphTo $query): void { + assertType('Illuminate\Database\Eloquent\Relations\MorphTo', $query); }])); assertType('Illuminate\Database\Eloquent\Builder', $query->without('relation')); assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation'])); assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation' => ['foo' => fn ($q) => $q]])); - assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); + assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation' => function (MorphTo $query) { + assertType('Illuminate\Database\Eloquent\Relations\MorphTo', $query); + }])); + assertType('Illuminate\Database\Eloquent\Builder', $query->withOnly(['relation' => function (HasOne $query): void { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); }])); assertType('array', $query->getModels()); assertType('array', $query->eagerLoadRelations([])); diff --git a/types/Database/Eloquent/Collection.php b/types/Database/Eloquent/Collection.php index 48933d24eef1..82185717c372 100644 --- a/types/Database/Eloquent/Collection.php +++ b/types/Database/Eloquent/Collection.php @@ -1,5 +1,10 @@ ', $collection->load('string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string' => ['foo' => fn ($q) => $q]])); -assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->load(['string' => function (BelongsTo $query) { + assertType('Illuminate\Database\Eloquent\Relations\BelongsTo', $query); }])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate('string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string'], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string' => ['foo' => fn ($q) => $q]], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string'], 'string', 'string')); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAggregate(['string' => function (BelongsTo $query) { + assertType('Illuminate\Database\Eloquent\Relations\BelongsTo', $query); }], 'string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadCount('string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadCount(['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadCount(['string' => ['foo' => fn ($q) => $q]])); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadCount(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadCount(['string' => function (HasOne $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); }])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMax('string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMax(['string'], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMax(['string' => ['foo' => fn ($q) => $q]], 'string')); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMax(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMax(['string' => function (HasMany $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasMany', $query); }], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMin('string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMin(['string'], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMin(['string' => ['foo' => fn ($q) => $q]], 'string')); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMin(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMin(['string' => function (HasOne $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); }], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadSum('string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadSum(['string'], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadSum(['string' => ['foo' => fn ($q) => $q]], 'string')); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadSum(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadSum(['string' => function (HasMany $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasMany', $query); }], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAvg('string', 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAvg(['string'], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAvg(['string' => ['foo' => fn ($q) => $q]], 'string')); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAvg(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadAvg(['string' => function (BelongsTo $query) { + assertType('Illuminate\Database\Eloquent\Relations\BelongsTo', $query); }], 'string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadExists('string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadExists(['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadExists(['string' => ['foo' => fn ($q) => $q]])); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadExists(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadExists(['string' => function (MorphTo $query) { + assertType('Illuminate\Database\Eloquent\Relations\MorphTo', $query); }])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMissing('string')); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMissing(['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMissing(['string' => ['foo' => fn ($q) => $q]])); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMissing(['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMissing(['string' => function (HasOne $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); }])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorph('string', ['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorph('string', ['string' => ['foo' => fn ($q) => $q]])); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorph('string', ['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorph('string', ['string' => function (HasMany $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasMany', $query); }])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorphCount('string', ['string'])); assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorphCount('string', ['string' => ['foo' => fn ($q) => $q]])); -assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorphCount('string', ['string' => function ($query) { - // assertType('Illuminate\Database\Eloquent\Relations\Relation<*,*,*>', $query); +assertType('Illuminate\Database\Eloquent\Collection', $collection->loadMorphCount('string', ['string' => function (HasOne $query) { + assertType('Illuminate\Database\Eloquent\Relations\HasOne', $query); }])); assertType('bool', $collection->contains(function ($user) {