@@ -356,3 +356,56 @@ Feature: Eloquent Relation types
356
356
"""
357
357
When I run Psalm
358
358
Then I see no errors
359
+
360
+ Scenario : cannot call firstOrNew and firstOrCreate without parameters in Laravel 6.x
361
+ Given I have the "laravel/framework" package satisfying the "6.*"
362
+ And I have the following code
363
+ """
364
+ function test_hasOne_firstOrCreate(User $user): Phone {
365
+ return $user->phone()->firstOrCreate();
366
+ }
367
+
368
+ function test_hasOne_firstOrNew(User $user): Phone {
369
+ return $user->phone()->firstOrNew();
370
+ }
371
+
372
+ function test_hasMany_firstOrCreate(Post $post): Comment {
373
+ return $post->comments()->firstOrCreate();
374
+ }
375
+
376
+ function test_hasMany_firstOrNew(Post $post): Comment {
377
+ return $post->comments()->firstOrNew();
378
+ }
379
+ """
380
+ When I run Psalm
381
+ Then I see these errors
382
+ | Type | Message |
383
+ | TooFewArguments | Too few arguments for method Illuminate \Database \Eloquent \Relations \HasOneOrMany ::firstorcreate saw 0 |
384
+ | TooFewArguments | Too few arguments for method Illuminate \Database \Eloquent \Relations \HasOneOrMany ::firstornew saw 0 |
385
+ | TooFewArguments | Too few arguments for method Illuminate \Database \Eloquent \Relations \HasOneOrMany ::firstorcreate saw 0 |
386
+ | TooFewArguments | Too few arguments for method Illuminate \Database \Eloquent \Relations \HasOneOrMany ::firstornew saw 0 |
387
+
388
+
389
+ Scenario : can call firstOrNew and firstOrCreate without parameters in Laravel 8.x
390
+ Given I have the "laravel/framework" package satisfying the ">= 8.0"
391
+ And I have the following code
392
+ """
393
+ function test_hasOne_firstOrCreate(User $user): Phone {
394
+ return $user->phone()->firstOrCreate();
395
+ }
396
+
397
+ function test_hasOne_firstOrNew(User $user): Phone {
398
+ return $user->phone()->firstOrNew();
399
+ }
400
+
401
+ function test_hasMany_firstOrCreate(Post $post): Comment {
402
+ return $post->comments()->firstOrCreate();
403
+ }
404
+
405
+ function test_hasMany_firstOrNew(Post $post): Comment {
406
+ return $post->comments()->firstOrNew();
407
+ }
408
+ """
409
+ When I run Psalm
410
+ Then I see no errors
411
+
0 commit comments