30 lines
773 B
PHP
30 lines
773 B
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Product;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ProductFactory extends Factory
|
|
{
|
|
protected $model = Product::class;
|
|
|
|
public function definition(): array
|
|
{
|
|
$name = $this->faker->unique()->words(2, true);
|
|
|
|
return [
|
|
'name' => Str::title($name),
|
|
'slug' => Str::slug($name.'-'.$this->faker->unique()->randomNumber()),
|
|
'cost_price' => $this->faker->numberBetween(20000, 150000),
|
|
'sale_price' => $this->faker->numberBetween(30000, 200000),
|
|
];
|
|
}
|
|
|
|
public function withDescription(): Factory
|
|
{
|
|
return $this->state(fn () => ['description' => $this->faker->paragraph()]);
|
|
}
|
|
}
|