first commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user