*/ class StoreFactory extends Factory { protected $model = Store::class; /** * Define the model's default state. * * @return array */ public function definition(): array { $master = Employee::where('store_id', 0)->inRandomOrder()->first(); return [ 'title' => $this->faker->word(), 'master_id' => $master->id, 'category_id' => Keyword::where('lv', 3)->where('parent_key', 'store_category')->inRandomOrder()->value('key'), 'business_id' => Keyword::where('lv', 2)->where('parent_key', 'store_business')->inRandomOrder()->value('key'), 'level_id' => Keyword::where('lv', 2)->where('parent_key', 'store_level')->inRandomOrder()->value('key'), 'region' => ['city' => '通辽市', 'code' => 150500, 'street' => null, 'cityCode' => 150500, 'district' => null, 'province' => '内蒙古自治区', 'districtCode' => 0, 'provinceCode' => 150000], 'lon' => '107.11352677389', 'lat' => '29.167519061656', 'address' => '重庆市南川区东城街道办事处东环路三号', ]; } public function configure(): static { return $this->afterMaking(function (Store $model) { })->afterCreating(function (Store $model) { Employee::where('id', $model->master_id)->update(['store_id' => $model->id]); }); } }