From c0cac8dcaf43ecb88498c725b51c8be6ff6ccd8c Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Wed, 26 Jun 2024 11:05:16 -0700 Subject: [PATCH] Fix issues with seeded data --- app/Repositories/ArtworkRepository.php | 14 ++++++-------- database/seeders/ArtworkSeeder.php | 8 ++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/Repositories/ArtworkRepository.php b/app/Repositories/ArtworkRepository.php index fed544d..320a5ff 100644 --- a/app/Repositories/ArtworkRepository.php +++ b/app/Repositories/ArtworkRepository.php @@ -44,16 +44,14 @@ public function prepareFieldsBeforeCreate(array $fields): array $apiFields['floor'] = $galleryFields['floor'] ?? null; } - $artist = Str::of($apiFields['artist_title'] ?: $apiFields['artist_display']) - ->before("\n")->trim()->__toString(); + if (! data_get($fields, "artist.en")) { + $artist = Str::of($apiFields['artist_title'] ?: $apiFields['artist_display']) + ->before("\n")->trim()->__toString(); - $translatedFields = [ - 'artist' => [ - 'en' => $artist, - ], - ]; + data_set($fields, "artist.en", $artist); + } - return parent::prepareFieldsBeforeCreate([...$fields, ...$apiFields, ...$translatedFields]); + return parent::prepareFieldsBeforeCreate([...$fields, ...$apiFields]); } public function afterSave(TwillModelContract $model, array $fields): void diff --git a/database/seeders/ArtworkSeeder.php b/database/seeders/ArtworkSeeder.php index 21118db..9d33cfb 100644 --- a/database/seeders/ArtworkSeeder.php +++ b/database/seeders/ArtworkSeeder.php @@ -45,7 +45,7 @@ public function run(ThemePrompt $themePrompt, array $artworks): void 'en' => [ 'title' => $rawArtwork['title'], 'artist' => $rawArtwork['artist'], - 'location_directions' => $rawArtwork['locationDirections'] ?? null, + 'locationDirections' => $rawArtwork['locationDirections'] ?? null, ], ])->merge($rawArtwork['translations'])->map( fn ($translation, $locale) => [ @@ -70,9 +70,9 @@ public function run(ThemePrompt $themePrompt, array $artworks): void $themePromptArtworkData = collect([ 'en' => [ - 'detail_narrative' => $rawArtwork['detailNarrative'] ?? null, - 'viewing_description' => $rawArtwork['viewingDescription'] ?? null, - 'activity_instructions' => $rawArtwork['activityInstructions'] ?? null, + 'detailNarrative' => $rawArtwork['detailNarrative'] ?? null, + 'viewingDescription' => $rawArtwork['viewingDescription'] ?? null, + 'activityInstructions' => $rawArtwork['activityInstructions'] ?? null, ], ])->merge($rawArtwork['translations'])->map( fn ($translation, $locale) => [