From 98c71674546807aa7ea0acd316cce78493faffc9 Mon Sep 17 00:00:00 2001 From: fatihalp Date: Wed, 4 Mar 2026 23:32:30 +0300 Subject: [PATCH] Enhance ListingSeeder and LocationSeeder with improved data handling and structure --- .../Database/Seeders/ListingSeeder.php | 48 ------- .../database/seeders/ListingSeeder.php | 133 ------------------ 2 files changed, 181 deletions(-) delete mode 100644 Modules/Listing/Database/Seeders/ListingSeeder.php delete mode 100644 Modules/Listing/database/seeders/ListingSeeder.php diff --git a/Modules/Listing/Database/Seeders/ListingSeeder.php b/Modules/Listing/Database/Seeders/ListingSeeder.php deleted file mode 100644 index d808d94a4..000000000 --- a/Modules/Listing/Database/Seeders/ListingSeeder.php +++ /dev/null @@ -1,48 +0,0 @@ -first(); - $categories = Category::where('level', 0)->get(); - - if (!$user || $categories->isEmpty()) return; - - $listings = [ - ['title' => 'iPhone 14 Pro - Excellent Condition', 'price' => 799, 'city' => 'Istanbul', 'country' => 'Turkey'], - ['title' => 'MacBook Pro 2023', 'price' => 1499, 'city' => 'Ankara', 'country' => 'Turkey'], - ['title' => '2020 Toyota Corolla', 'price' => 18000, 'city' => 'New York', 'country' => 'United States'], - ['title' => '3-Bedroom Apartment for Sale', 'price' => 250000, 'city' => 'Istanbul', 'country' => 'Turkey'], - ['title' => 'Nike Running Shoes Size 42', 'price' => 89, 'city' => 'Berlin', 'country' => 'Germany'], - ['title' => 'IKEA Dining Table', 'price' => 150, 'city' => 'London', 'country' => 'United Kingdom'], - ['title' => 'Yoga Mat - Brand New', 'price' => 35, 'city' => 'Paris', 'country' => 'France'], - ['title' => 'Web Developer for Hire', 'price' => 0, 'city' => 'Remote', 'country' => 'Turkey'], - ['title' => 'Samsung 55" 4K TV', 'price' => 599, 'city' => 'Madrid', 'country' => 'Spain'], - ['title' => 'Honda CBR500R Motorcycle 2021', 'price' => 6500, 'city' => 'Tokyo', 'country' => 'Japan'], - ]; - - foreach ($listings as $i => $listing) { - $category = $categories->get($i % $categories->count()); - Listing::firstOrCreate( - ['slug' => \Illuminate\Support\Str::slug($listing['title']) . '-' . ($i + 1)], - array_merge($listing, [ - 'slug' => \Illuminate\Support\Str::slug($listing['title']) . '-' . ($i + 1), - 'description' => 'This is a sample listing description for ' . $listing['title'], - 'currency' => $listing['price'] > 0 ? 'USD' : 'USD', - 'category_id' => $category?->id, - 'user_id' => $user->id, - 'status' => 'active', - 'contact_email' => 'partner@openclassify.com', - 'contact_phone' => '+1234567890', - 'is_featured' => $i < 3, - ]) - ); - } - } -} diff --git a/Modules/Listing/database/seeders/ListingSeeder.php b/Modules/Listing/database/seeders/ListingSeeder.php deleted file mode 100644 index 0267b90d1..000000000 --- a/Modules/Listing/database/seeders/ListingSeeder.php +++ /dev/null @@ -1,133 +0,0 @@ -orWhere('email', 'partner@openclassify.com') - ->first(); - $categories = Category::where('level', 0)->get(); - - if (!$user || $categories->isEmpty()) return; - - $listings = [ - [ - 'title' => 'iPhone 14 Pro 256 GB, temiz kullanılmış', - 'description' => 'Cihaz sorunsuz çalışıyor, pil sağlığı iyi durumda. Kutusu ve şarj kablosu ile teslim edilecektir.', - 'price' => 44999, - 'city' => 'İstanbul', - 'country' => 'Türkiye', - ], - [ - 'title' => 'MacBook Pro M2 16 GB / 512 GB', - 'description' => 'Yazılım geliştirme için kullanıldı. Kozmetik olarak çok iyi durumda, faturası mevcut.', - 'price' => 62999, - 'city' => 'Ankara', - 'country' => 'Türkiye', - ], - [ - 'title' => '2020 Toyota Corolla 1.6 Dream', - 'description' => 'Boyalı parça yok, düzenli bakımlı aile aracı. Detaylı ekspertiz raporu paylaşılabilir.', - 'price' => 980000, - 'city' => 'İzmir', - 'country' => 'Türkiye', - ], - [ - 'title' => 'Bluetooth Kulaklık - Aktif Gürültü Engelleme', - 'description' => 'Uzun pil ömrü ve net mikrofon performansı. Kutu içeriği tamdır.', - 'price' => 3499, - 'city' => 'Bursa', - 'country' => 'Türkiye', - ], - [ - 'title' => 'Masaüstü için 15 inç dizüstü bilgisayar', - 'description' => 'Günlük kullanım ve ofis işleri için ideal. SSD sayesinde hızlı açılış.', - 'price' => 18450, - 'city' => 'Antalya', - 'country' => 'Türkiye', - ], - [ - 'title' => 'Seramik Kahve Kupası Seti (6 Adet)', - 'description' => 'Az kullanıldı, kırık/çatlak yok. Mutfak yenileme nedeniyle satılıktır.', - 'price' => 650, - 'city' => 'Adana', - 'country' => 'Türkiye', - ], - [ - 'title' => 'Sedan Araç - Düşük Kilometre', - 'description' => 'Şehir içi kullanıldı, tüm bakımları zamanında yapıldı. Ciddi alıcılarla paylaşım yapılır.', - 'price' => 845000, - 'city' => 'Konya', - 'country' => 'Türkiye', - ], - ]; - - $sampleImages = [ - 'sample_image/phone.jpeg', - 'sample_image/macbook.jpg', - 'sample_image/car.jpeg', - 'sample_image/headphones.jpg', - 'sample_image/laptop.jpg', - 'sample_image/cup.jpg', - 'sample_image/car2.jpeg', - ]; - - $sampleImageFileNames = collect($sampleImages) - ->map(fn (string $path): string => basename($path)) - ->values(); - - foreach ($listings as $i => $listing) { - $category = $categories->get($i % $categories->count()); - $slug = Str::slug($listing['title']) . '-' . ($i + 1); - - $listingModel = Listing::updateOrCreate( - ['slug' => $slug], - array_merge($listing, [ - 'slug' => $slug, - 'description' => $listing['description'], - 'currency' => 'TRY', - 'category_id' => $category?->id, - 'user_id' => $user->id, - 'status' => 'active', - 'contact_email' => $user->email, - 'contact_phone' => '+905551112233', - 'is_featured' => $i < 3, - ]) - ); - - $imageRelativePath = $sampleImages[$i % count($sampleImages)]; - $imageAbsolutePath = public_path($imageRelativePath); - - if (! is_file($imageAbsolutePath)) { - continue; - } - - $currentMedia = $listingModel->getMedia('listing-images'); - $currentHasSampleImage = $currentMedia->contains( - fn ($media): bool => $sampleImageFileNames->contains((string) $media->file_name) - ); - - if (! $currentHasSampleImage) { - $listingModel->clearMediaCollection('listing-images'); - } - - $targetFileName = basename($imageAbsolutePath); - $alreadyHasTargetImage = $listingModel->getMedia('listing-images') - ->contains(fn ($media): bool => (string) $media->file_name === $targetFileName); - - if (! $alreadyHasTargetImage) { - $listingModel - ->addMedia($imageAbsolutePath) - ->preservingOriginal() - ->toMediaCollection('listing-images'); - } - } - } -}