39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Brand;
|
|
use App\Models\Category;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Product>
|
|
*/
|
|
class ProductFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$name = Str::title(fake()->words(fake()->numberBetween(2, 5), true));
|
|
|
|
return [
|
|
'category_id' => Category::factory(),
|
|
'brand_id' => Brand::factory(),
|
|
'name' => $name,
|
|
'slug' => Str::slug($name).'-'.fake()->unique()->numberBetween(100, 999),
|
|
'sku' => strtoupper(fake()->bothify('SKU-#####??')),
|
|
'short_description' => fake()->optional()->sentence(),
|
|
'description' => fake()->paragraphs(2, true),
|
|
'thumbnail_path' => null,
|
|
'price' => fake()->randomFloat(2, 10, 10000),
|
|
'stock_quantity' => fake()->numberBetween(0, 5000),
|
|
'active' => fake()->boolean(90),
|
|
'published_at' => fake()->optional(0.8)->dateTimeBetween('-1 year', 'now'),
|
|
];
|
|
}
|
|
}
|