Files
HRM-System/database/factories/ProductFactory.php
2026-04-13 08:16:56 +08:00

30 lines
1007 B
PHP

<?php
namespace Database\Factories;
use App\Models\Category;
use App\Models\Product;
use Illuminate\Database\Eloquent\Factories\Factory;
class ProductFactory extends Factory
{
protected $model = Product::class;
public function definition(): array
{
return [
'name' => $this->faker->words(3, true),
'description' => $this->faker->paragraph(),
'price' => $this->faker->randomFloat(2, 10, 1000),
'category_id' => function () {
return Category::inRandomOrder()->first()->id ?? null;
},
'featured_image' => 'products/product-' . $this->faker->numberBetween(1, 10) . '.jpg',
'featured_image_original_name' => 'product-image.jpg',
'created_at' => $this->faker->dateTimeBetween('-6 months', 'now'),
'updated_at' => function (array $attributes) {
return $this->faker->dateTimeBetween($attributes['created_at'], 'now');
},
];
}
}