34 lines
705 B
PHP
34 lines
705 B
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Category;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends Factory<Category>
|
|
*/
|
|
class CategoryFactory extends Factory
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
$name = fake()->unique()->words(2, true);
|
|
|
|
return [
|
|
'parent_id' => null,
|
|
'name' => Str::title($name),
|
|
'slug' => Str::slug($name),
|
|
'description' => fake()->sentence(),
|
|
];
|
|
}
|
|
|
|
public function childOf(Category $parent): static
|
|
{
|
|
return $this->state(fn () => ['parent_id' => $parent->id]);
|
|
}
|
|
}
|