@@ -60,32 +60,33 @@ class ProductFactory extends Factory
6060 public function definition(): array
6161 {
6262 return [
63- 'name' => $this->faker->passThrough(ucfirst($this->faker->text( 255) )),
64- 'address' => $this->faker ->address(),
65- 'slug' => $this->faker ->unique()->slug(),
66- 'description' => $this->faker ->optional()->sentences(3, true),
67- 'price' => $this->faker ->randomFloat(2, 0, 999999999999),
68- 'stock' => $this->faker ->numberBetween(0, 4294967295),
69- 'on_sale' => $this->faker ->boolean(),
70- 'features' => $this->faker->passThrough($this->faker-> words() ),
71- 'published_at' => $this->faker ->dateTime()?->format('Y-m-d H:i'),
72- 'expire_at' => $this->faker ->dateTime()?->format('Y-m-d H:i'),
73- 'released_on' => $this->faker ->date(),
74- 'sale_time' => $this->faker ->time(),
75- 'status' => $this->faker ->randomElement(['draft', 'published']),
76- 'manufactured_year' => $this->faker ->year(2100),
63+ 'name' => fake()->text(fake()->numberBetween(5, 255)),
64+ 'address' => fake() ->address(),
65+ 'slug' => fake() ->unique()->slug(),
66+ 'description' => fake() ->optional()->sentences(3, true),
67+ 'price' => fake() ->randomFloat(2, 0, 999999999999),
68+ 'stock' => fake() ->numberBetween(0, 4294967295),
69+ 'on_sale' => fake() ->boolean(),
70+ 'features' => fake()-> words(),
71+ 'published_at' => fake() ->dateTime()?->format('Y-m-d H:i'),
72+ 'expire_at' => fake() ->dateTime()?->format('Y-m-d H:i'),
73+ 'released_on' => fake() ->date(),
74+ 'sale_time' => fake() ->time(),
75+ 'status' => fake() ->randomElement(['draft', 'published']),
76+ 'manufactured_year' => fake() ->year(2100),
7777 ];
7878 }
7979
8080 public function withCategory(): ProductFactory
8181 {
8282 return $this->state(function (array $attributes) {
8383 return [
84- 'category_id' => $this->faker-> passThrough(random_id_or_generate(\App\Models\Category::class, 'id')),
84+ 'category_id' => fake()-> passThrough(random_id_or_generate(\App\Models\Category::class, 'id', generate: true )),
8585 ];
8686 });
8787 }
8888}
89+
8990```
9091
9192# Generating for specific columns
@@ -120,8 +121,8 @@ class ProductFactory extends Factory
120121 public function definition(): array
121122 {
122123 return [
123- 'name' => $this->faker->passThrough(ucfirst($this->faker->text( 255) )),
124- 'address' => $this->faker ->address(),
124+ 'name' => fake()->text(fake()->numberBetween(5, 255)),
125+ 'address' => fake() ->address(),
125126 ];
126127 }
127128}
0 commit comments