44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Product;
|
|
use App\Models\Project;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
class ProductFactory extends Factory
|
|
{
|
|
protected $model = Product::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$type = $this->faker->randomElement(['LAND', 'APARTMENT']);
|
|
$area = $this->faker->randomFloat(2, 50, 200);
|
|
$pricePerUnit = $this->faker->numberBetween(20, 100) * 1000000; // 20M to 100M VND
|
|
|
|
$customData = match ($type) {
|
|
'LAND' => [
|
|
'frontage' => $this->faker->numberBetween(1, 3),
|
|
'road_width' => $this->faker->numberBetween(6, 30),
|
|
],
|
|
'APARTMENT' => [
|
|
'block' => $this->faker->randomElement(['A', 'B', 'C']),
|
|
'floor' => $this->faker->numberBetween(2, 30),
|
|
'view' => $this->faker->randomElement(['Hồ bơi', 'Công viên', 'Thành phố']),
|
|
],
|
|
};
|
|
|
|
return [
|
|
'project_id' => Project::factory(),
|
|
'product_type' => $type,
|
|
'code' => 'STH-' . $this->faker->unique()->numberBetween(1000, 9999),
|
|
'area' => $area,
|
|
'price_per_unit' => $pricePerUnit,
|
|
'total_price' => $area * $pricePerUnit,
|
|
'custom_data' => $customData,
|
|
'status' => 'Đang mở bán',
|
|
'red_book_status' => 'Chưa có dữ liệu',
|
|
];
|
|
}
|
|
}
|