From e83bd6981daa402a3a75e53a81f4677584e44a61 Mon Sep 17 00:00:00 2001 From: Yutaka Kurosaki <> Date: Sun, 10 May 2026 11:58:41 +0900 Subject: [PATCH] Fix DocumentFactory withoutTranslations + path trailing period afterCreating appends rather than replaces, so a no-op closure does not override configure(). Use withoutAfterCreating() to actually clear the translation-creation callback (otherwise DocumentTranslation::factory() recurses through Document::factory()->withoutTranslations()). Also use words() instead of sentence() to avoid Faker's trailing period producing paths like "Foo bar..md". Co-Authored-By: Claude Sonnet 4.6 --- src/database/factories/DocumentFactory.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/database/factories/DocumentFactory.php b/src/database/factories/DocumentFactory.php index 017a6c2..064b979 100644 --- a/src/database/factories/DocumentFactory.php +++ b/src/database/factories/DocumentFactory.php @@ -16,7 +16,7 @@ class DocumentFactory extends Factory public function definition(): array { - $title = fake()->unique()->sentence(3); + $title = rtrim(fake()->unique()->words(3, true), '.'); return [ 'path' => $title . '.md', @@ -29,8 +29,9 @@ public function definition(): array } /** - * After creating, attach a translation in the document's default_locale. - * Pass an explicit ['title' => ..., 'content' => ...] via withTranslation() to override. + * After creating, attach a translation in the document's default_locale + * (skipped if a translation was already created via state, or if the + * caller used withoutTranslations()). */ public function configure(): static { @@ -45,7 +46,7 @@ public function configure(): static } /** - * Override the default_locale and create the corresponding translation. + * Override the default_locale (auto-translation will be created in this locale). */ public function defaultLocale(string $locale): static { @@ -53,10 +54,12 @@ public function defaultLocale(string $locale): static } /** - * Suppress automatic translation creation (caller will create manually). + * Suppress automatic translation creation. Uses Laravel's built-in + * withoutAfterCreating() to clear callbacks rather than appending a no-op + * (afterCreating appends, so a no-op closure does NOT override the configure() callback). */ public function withoutTranslations(): static { - return $this->afterCreating(fn () => null); + return $this->withoutAfterCreating(); } }