File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
src/Illuminate/Database/Eloquent/Factories Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ class BelongsToManyRelationship
10
10
/**
11
11
* The related factory instance.
12
12
*
13
- * @var \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model
13
+ * @var \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array
14
14
*/
15
15
protected $ factory ;
16
16
@@ -31,7 +31,7 @@ class BelongsToManyRelationship
31
31
/**
32
32
* Create a new attached relationship definition.
33
33
*
34
- * @param \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $factory
34
+ * @param \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $factory
35
35
* @param callable|array $pivot
36
36
* @param string $relationship
37
37
* @return void
Original file line number Diff line number Diff line change @@ -569,7 +569,7 @@ protected function guessRelationship(string $related)
569
569
/**
570
570
* Define an attached relationship for the model.
571
571
*
572
- * @param \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $factory
572
+ * @param \Illuminate\Database\Eloquent\Factories\Factory|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model|array $factory
573
573
* @param (callable(): array<string, mixed>)|array<string, mixed> $pivot
574
574
* @param string|null $relationship
575
575
* @return static
Original file line number Diff line number Diff line change @@ -378,6 +378,29 @@ public function test_belongs_to_many_relationship_with_existing_model_instances(
378
378
unset($ _SERVER ['__test.role.creating-role ' ]);
379
379
}
380
380
381
+ public function test_belongs_to_many_relationship_with_existing_model_instances_using_array ()
382
+ {
383
+ $ roles = FactoryTestRoleFactory::times (3 )
384
+ ->afterCreating (function ($ role ) {
385
+ $ _SERVER ['__test.role.creating-role ' ] = $ role ;
386
+ })
387
+ ->create ();
388
+ FactoryTestUserFactory::times (3 )
389
+ ->hasAttached ($ roles ->toArray (), ['admin ' => 'Y ' ], 'roles ' )
390
+ ->create ();
391
+
392
+ $ this ->assertCount (3 , FactoryTestRole::all ());
393
+
394
+ $ user = FactoryTestUser::latest ()->first ();
395
+
396
+ $ this ->assertCount (3 , $ user ->roles );
397
+ $ this ->assertSame ('Y ' , $ user ->roles ->first ()->pivot ->admin );
398
+
399
+ $ this ->assertInstanceOf (Eloquent::class, $ _SERVER ['__test.role.creating-role ' ]);
400
+
401
+ unset($ _SERVER ['__test.role.creating-role ' ]);
402
+ }
403
+
381
404
public function test_belongs_to_many_relationship_with_existing_model_instances_with_relationship_name_implied_from_model ()
382
405
{
383
406
$ roles = FactoryTestRoleFactory::times (3 )
You can’t perform that action at this time.
0 commit comments