Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a9974f

Browse files
committed
Document array usages for find methods
1 parent c24acb6 commit 7a9974f

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

stubs/database/eloquent/builder.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ class Builder implements BuilderContract
5757
/**
5858
* @param mixed $id
5959
* @param string[]|string $columns
60-
* @return TModel
60+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TCollection : TModel)
6161
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException<TModel>
6262
*/
6363
public function findOrFail($id, $columns = ['*']);
6464

6565
/**
6666
* @param mixed $id
6767
* @param string[]|string $columns
68-
* @return TModel
68+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TCollection : TModel)
6969
*/
7070
public function findOrNew($id, $columns = ['*']);
7171

stubs/database/eloquent/relations/belongs-to-many.stub

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BelongsToMany extends Relation
1515
/**
1616
* @param mixed $id
1717
* @param string[] $columns
18-
* @return TRelated
18+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TRelatedCollection : TRelated)
1919
*/
2020
public function findOrNew($id, $columns = ['*']);
2121

@@ -56,7 +56,7 @@ class BelongsToMany extends Relation
5656
/**
5757
* @param mixed $id
5858
* @param string[] $columns
59-
* @return TRelated|null
59+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TRelatedCollection : TRelated|null)
6060
*/
6161
public function find($id, $columns = ['*']);
6262

@@ -70,17 +70,17 @@ class BelongsToMany extends Relation
7070
/**
7171
* @param mixed $id
7272
* @param string[] $columns
73-
* @return TRelated
73+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TRelatedCollection : TRelated)
7474
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException<TRelated>
7575
*/
7676
public function findOrFail($id, $columns = ['*']);
7777

7878
/**
79-
* @template TOther
79+
* @template TReturn
8080
* @param mixed $id
81-
* @param \Closure(): TOther|array $columns
82-
* @param \Closure(): TOther|null $callback
83-
* @return TRelated|TOther
81+
* @param (\Closure(): TReturn)|array $columns
82+
* @param (\Closure(): TReturn)|null $callback
83+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TRelatedCollection : TRelated|TReturn)
8484
*/
8585
public function findOr($id, $columns = ['*'], ?Closure $callback = null);
8686

stubs/database/eloquent/relations/has-one-or-many.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class HasOneOrMany extends Relation
2727
/**
2828
* @param mixed $id
2929
* @param string[] $columns
30-
* @return TRelated
30+
* @return ($id is \Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed> ? TRelatedCollection : TRelated)
3131
*/
3232
public function findOrNew($id, $columns = ['*']);
3333

tests/Types/data/database/eloquent/relations/belongs-to-many.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
/** @var \Tests\Types\Fakes\Category $category */
77

88
assertType('Tests\Types\Fakes\Category', $relation->findOrNew(1));
9+
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Category>', $relation->findOrNew([1]));
910
assertType('Tests\Types\Fakes\Category', $relation->firstOrNew());
1011
assertType('Tests\Types\Fakes\Category', $relation->firstOrCreate());
1112
assertType('Tests\Types\Fakes\Category', $relation->createOrFirst());
1213
assertType('Tests\Types\Fakes\Category', $relation->updateOrCreate(['foo' => 'bar']));
1314
assertType('Tests\Types\Fakes\Category|null', $relation->find(1));
15+
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Category>', $relation->find([1]));
1416
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Category>', $relation->findMany([1]));
1517
assertType('Tests\Types\Fakes\Category', $relation->findOrFail(1));
18+
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Category>', $relation->findOrFail([1]));
1619
assertType('string|Tests\Types\Fakes\Category', $relation->findOr(1, fn () => 'foo-bar'));
20+
assertType('string|Tests\Types\Fakes\Category', $relation->findOr(1, fn () => 'foo-bar'));
21+
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Category>', $relation->findOr([1], ['*'], fn () => 'foo-bar'));
22+
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Category>', $relation->findOr([1], fn () => 'foo-bar'));
1723
assertType('Tests\Types\Fakes\Category|null', $relation->firstWhere('foo', 'bar'));
1824
assertType('Tests\Types\Fakes\Category|null', $relation->first());
1925
assertType('Tests\Types\Fakes\Category', $relation->firstOrFail());

tests/Types/data/database/eloquent/relations/has-one-or-many.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
assertType('Tests\Types\Fakes\Post', $relation->make(['foo' => 'bar']));
99
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Post>', $relation->makeMany([['foo' => 'bar']]));
1010
assertType('Tests\Types\Fakes\Post', $relation->findOrNew(1));
11+
assertType('Illuminate\Database\Eloquent\Collection<int, Tests\Types\Fakes\Post>', $relation->findOrNew([1]));
1112
assertType('Tests\Types\Fakes\Post', $relation->firstOrNew(['foo' => 'bar']));
1213
assertType('Tests\Types\Fakes\Post', $relation->firstOrCreate(['foo' => 'bar']));
1314
assertType('Tests\Types\Fakes\Post', $relation->createOrFirst(['foo' => 'bar']));

0 commit comments

Comments
 (0)