Closed ishanvyas22 closed 1 year ago
Currently it is not possible to set values that are nested.
class ExampleFactory extends BaseFactory { ... protected function setDefaultTemplate(): void { $this->setDefaultData(function (Generator $faker) { return [ 'name' => $faker->name, 'data' => [ 'mobile' => 123456, 'email' => $faker->email, ], 'created' => FrozenTime::now(), 'modified' => FrozenTime::now(), ]; }); } ... }
For above factory, this works:
ExampleFactory::make(['name' => 'John Doe'])->persist();
this doesn't:
ExampleFactory::make(['data' => ['email' => 'foo@example.org']])->persist();
Above will overwrite the whole data array values instead of just updating the data.email field.
data
data.email
It would be a nice to allow developers to set nested values as well.
Simply provide array:
Using dot notation:
ExampleFactory::make(['data.email' => 'foo@example.org'])->persist();
Whichever options works best.
Thanks for the proposal @ishanvyas22 ! The dot notation is indeed a nice way to specify that a nested value should be inserted.
@pakacuda is this good for you?
Merged with v3.9
Problem
Currently it is not possible to set values that are nested.
For above factory, this works:
this doesn't:
Above will overwrite the whole
data
array values instead of just updating thedata.email
field.Proposal
It would be a nice to allow developers to set nested values as well.
Option 1
Simply provide array:
Option 2
Using dot notation:
Whichever options works best.