22
33namespace Illuminate \Types \Model ;
44
5+ use Illuminate \Database \Eloquent \Collection ;
56use Illuminate \Database \Eloquent \Model ;
67use User ;
78
89use function PHPStan \Testing \assertType ;
910
10- function test (User $ user ): void
11+ function test (User $ user, Post $ post , Comment $ comment ): void
1112{
1213 assertType ('UserFactory ' , User::factory (function ($ attributes , $ model ) {
1314 assertType ('array<string, mixed> ' , $ attributes );
@@ -31,7 +32,8 @@ function test(User $user): void
3132 assertType ('Illuminate\Database\Eloquent\Relations\MorphMany<Illuminate\Notifications\DatabaseNotification, User> ' , $ user ->notifications ());
3233
3334 assertType ('Illuminate\Database\Eloquent\Collection<int, User> ' , $ user ->newCollection ([new User ()]));
34- assertType ('Illuminate\Database\Eloquent\Collection<string, Illuminate\Types\Model\Post> ' , $ user ->newCollection (['foo ' => new Post ()]));
35+ assertType ('Illuminate\Database\Eloquent\Collection<string, Illuminate\Types\Model\Post> ' , $ post ->newCollection (['foo ' => new Post ()]));
36+ assertType ('Illuminate\Types\Model\Comments ' , $ comment ->newCollection ([new Comment ()]));
3537
3638 assertType ('bool ' , $ user ->restore ());
3739 assertType ('User ' , $ user ->restoreOrCreate ());
@@ -41,3 +43,16 @@ function test(User $user): void
4143class Post extends Model
4244{
4345}
46+
47+ final class Comment extends Model
48+ {
49+ public function newCollection (array $ models = []): Comments
50+ {
51+ return new Comments ($ models );
52+ }
53+ }
54+
55+ /** @extends Collection<array-key, Comment> */
56+ final class Comments extends Collection
57+ {
58+ }
0 commit comments