parfum/database/factories/CategoryFactory.php

30 lines
667 B
PHP

<?php
namespace Database\Factories;
use App\Models\Category;
use Illuminate\Database\Eloquent\Factories\Factory;
class CategoryFactory extends Factory
{
protected $model = Category::class;
public function definition(): array
{
return [
'name' => $this->faker->unique()->company(),
'slug' => $this->faker->slug(),
'sort_order' => function () {
$max = Category::max('sort_order') ?? 0;
return $max + 1;
},
];
}
public function withDescription(): Factory
{
return $this->state(fn () => ['description' => $this->faker->text()]);
}
}