*/ class CategoryFactory extends Factory { protected $model = Category::class; /** * @return array */ public function definition(): array { $name = $this->faker->unique()->words(2, true); return [ // Every supported locale gets a value so factory-made records // exercise the translation paths rather than the fallback. 'name' => $this->eachLocale(fn (string $locale) => ucfirst($name)." ({$locale})"), 'slug' => $this->eachLocale(fn (string $locale) => Str::slug($name."-{$locale}")), 'description' => $this->eachLocale(fn () => $this->faker->sentence()), 'color' => $this->faker->hexColor(), 'position' => $this->faker->numberBetween(0, 20), 'is_visible' => true, ]; } /** * @param callable(string): string $value * @return array */ protected function eachLocale(callable $value): array { return collect(array_keys(config('locales.supported'))) ->mapWithKeys(fn (string $locale) => [$locale => $value($locale)]) ->all(); } }