File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
src/Illuminate/Database/Eloquent/Factories Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -483,6 +483,18 @@ public function state($state)
483
483
]);
484
484
}
485
485
486
+ /**
487
+ * Set a single model attribute.
488
+ *
489
+ * @param string|int $key
490
+ * @param mixed $value
491
+ * @return static
492
+ */
493
+ public function set ($ key , $ value )
494
+ {
495
+ return $ this ->state ([$ key => $ value ]);
496
+ }
497
+
486
498
/**
487
499
* Add a new sequenced state transformation to the model definition.
488
500
*
Original file line number Diff line number Diff line change @@ -108,6 +108,10 @@ public function test_basic_model_can_be_created()
108
108
$ this ->assertInstanceOf (Eloquent::class, $ user );
109
109
$ this ->assertSame ('Taylor Otwell ' , $ user ->name );
110
110
111
+ $ user = FactoryTestUserFactory::new ()->set ('name ' , 'Taylor Otwell ' )->create ();
112
+ $ this ->assertInstanceOf (Eloquent::class, $ user );
113
+ $ this ->assertSame ('Taylor Otwell ' , $ user ->name );
114
+
111
115
$ users = FactoryTestUserFactory::new ()->createMany ([
112
116
['name ' => 'Taylor Otwell ' ],
113
117
['name ' => 'Jeffrey Way ' ],
You can’t perform that action at this time.
0 commit comments