*/ class MenuFactory extends Factory { /** * 다국어 필드 생성 */ protected function generateTranslatableField(callable $generator): array { $locales = config('app.translatable_locales', ['ko', 'en']); $data = []; foreach ($locales as $locale) { $data[$locale] = $generator(); } return $data; } /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'name' => $this->generateTranslatableField(fn () => $this->faker->words(2, true)), 'slug' => $this->faker->unique()->slug(), 'url' => '/admin/'.$this->faker->slug(), 'icon' => 'fas fa-'.$this->faker->randomElement(['home', 'user', 'cog', 'chart', 'file']), 'parent_id' => null, 'order' => $this->faker->numberBetween(1, 100), 'is_active' => true, // menus 스키마는 module_id 를 extension_type/extension_identifier 로 이행 'extension_type' => null, 'extension_identifier' => null, 'created_by' => User::factory(), ]; } /** * 비활성화된 메뉴 상태 */ public function inactive(): static { return $this->state(fn (array $attributes) => [ 'is_active' => false, ]); } /** * 모듈 메뉴 상태 */ public function moduleMenu(string $moduleIdentifier = 'sirsoft-ecommerce'): static { return $this->state(fn (array $attributes) => [ 'extension_type' => 'module', 'extension_identifier' => $moduleIdentifier, ]); } /** * 자식 메뉴 상태 */ public function childMenu(int $parentId): static { return $this->state(fn (array $attributes) => [ 'parent_id' => $parentId, ]); } /** * 코어 메뉴 상태 (기본값과 동일하지만 명시적) */ public function coreMenu(): static { return $this->state(fn (array $attributes) => [ 'extension_type' => 'core', 'extension_identifier' => 'core', ]); } }