* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; use InnoShop\Common\Models\Category; /** * @extends Factory */ class CategoryFactory extends Factory { protected $model = Category::class; public function definition(): array { $name = fake()->words(2, true); return [ 'parent_id' => null, 'slug' => Str::slug($name).'-'.Str::random(5), 'position' => fake()->numberBetween(0, 100), 'image' => null, 'active' => true, ]; } public function inactive(): static { return $this->state(fn (array $attributes) => [ 'active' => false, ]); } public function withParent(Category $parent): static { return $this->state(fn (array $attributes) => [ 'parent_id' => $parent->id, ]); } }