22
33namespace Moox \Tag \Database \Factories ;
44
5+ use Faker \Factory as FakerFactory ;
56use Illuminate \Database \Eloquent \Factories \Factory ;
6- use Illuminate \Support \Str ;
77use Moox \Tag \Models \Tag ;
88use Moox \Tag \Models \TagTranslation ;
9- use Faker \Factory as FakerFactory ;
109
1110class TagFactory extends Factory
1211{
@@ -70,7 +69,7 @@ public function configure(): static
7069 // Always create English translation by default
7170 $ title = $ this ->generateLocalizedTitle ('en ' );
7271 $ slug = TagTranslation::generateUniqueSlug ($ title , 'en ' );
73-
72+
7473 $ tag ->translateOrNew ('en ' )->fill ([
7574 'title ' => $ title ,
7675 'slug ' => $ slug ,
@@ -86,7 +85,7 @@ protected function generateLocalizedTitle(string $locale): string
8685 {
8786 $ faker = FakerFactory::create ($ this ->availableLocales [$ locale ]['faker_locale ' ]);
8887 $ sampleWords = $ this ->availableLocales [$ locale ]['sample_words ' ];
89-
88+
9089 // Mix faker words with sample words for more realistic content
9190 if ($ this ->faker ->boolean (30 )) {
9291 return $ this ->faker ->randomElement ($ sampleWords );
@@ -116,14 +115,14 @@ protected function generateLocalizedContent(string $locale): string
116115 */
117116 public function withTranslation (string $ locale ): self
118117 {
119- if (!isset ($ this ->availableLocales [$ locale ])) {
118+ if (! isset ($ this ->availableLocales [$ locale ])) {
120119 throw new \InvalidArgumentException ("Locale {$ locale } is not supported " );
121120 }
122121
123122 return $ this ->afterCreating (function (Tag $ tag ) use ($ locale ) {
124123 $ title = $ this ->generateLocalizedTitle ($ locale );
125124 $ slug = TagTranslation::generateUniqueSlug ($ title , $ locale );
126-
125+
127126 $ tag ->translateOrNew ($ locale )->fill ([
128127 'title ' => $ title ,
129128 'slug ' => $ slug ,
@@ -179,11 +178,13 @@ public function withAllTranslations(): self
179178 {
180179 return $ this ->afterCreating (function (Tag $ tag ) {
181180 foreach ($ this ->availableLocales as $ locale => $ config ) {
182- if ($ locale === 'en ' ) continue ; // Skip English as it's already created
183-
181+ if ($ locale === 'en ' ) {
182+ continue ;
183+ } // Skip English as it's already created
184+
184185 $ title = $ this ->generateLocalizedTitle ($ locale );
185186 $ slug = TagTranslation::generateUniqueSlug ($ title , $ locale );
186-
187+
187188 $ tag ->translateOrNew ($ locale )->fill ([
188189 'title ' => $ title ,
189190 'slug ' => $ slug ,
@@ -202,8 +203,8 @@ public function withRandomTranslations(int $count = 2): self
202203 $ locales = array_keys ($ this ->availableLocales );
203204 unset($ locales [array_search ('en ' , $ locales )]); // Remove English
204205 $ selectedLocales = array_rand (array_flip ($ locales ), min ($ count , count ($ locales )));
205-
206- foreach ((array )$ selectedLocales as $ locale ) {
206+
207+ foreach ((array ) $ selectedLocales as $ locale ) {
207208 $ this ->withTranslation ($ locale )->configure ()->afterCreating ->first ()($ tag );
208209 }
209210 });
0 commit comments