diff --git a/app/Filament/Resources/Categories/Schemas/CategoryForm.php b/app/Filament/Resources/Categories/Schemas/CategoryForm.php index 2fcea34..717c8c7 100644 --- a/app/Filament/Resources/Categories/Schemas/CategoryForm.php +++ b/app/Filament/Resources/Categories/Schemas/CategoryForm.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources\Categories\Schemas; +use Filament\Forms\Components\Select; use Filament\Forms\Components\TextInput; use Filament\Schemas\Schema; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index c25d86e..7b6c59b 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -18,10 +18,14 @@ class DatabaseSeeder extends Seeder { // User::factory(10)->create(); - User::factory()->create([ - 'name' => 'Admin', - 'email' => 'admin@example.com', - 'password' => Hash::make('password'), - ]); + if (User::where('email', 'admin@example.com')->doesntExist()) { + User::factory()->create([ + 'name' => 'Admin', + 'email' => 'admin@example.com', + 'password' => Hash::make('password'), + ]); + } + + $this->call(DemoSeeder::class); } } diff --git a/database/seeders/DemoSeeder.php b/database/seeders/DemoSeeder.php new file mode 100644 index 0000000..4f2e659 --- /dev/null +++ b/database/seeders/DemoSeeder.php @@ -0,0 +1,128 @@ +makeDirectory('slides'); + Storage::disk('public')->makeDirectory('products'); + Storage::disk('public')->makeDirectory('collections'); + + $this->command->info('Seeding Carousel Slides...'); + for ($i = 1; $i <= 3; $i++) { + $imagePath = 'slides/slide-'.$i.'.jpg'; + $this->generateDummyImage($imagePath, 1200, 600, 'Slide '.$i); + + CarouselSlide::create([ + 'title' => 'Täze harytlar '.$i, + 'subtitle' => 'Iň oňat bahalar bilen öýüňizi bezäň', + 'order' => $i, + 'is_active' => true, + 'image' => $imagePath, + ]); + } + + $this->command->info('Seeding Categories & Products...'); + $categories = ['Diwanlar', 'Krowatlar', 'Stollar', 'Oturgyçlar', 'Şkaflar']; + + foreach ($categories as $index => $categoryName) { + $category = Category::create([ + 'name' => $categoryName, + 'icon' => 'heroicon-o-archive-box', // dummy icon + 'order' => $index + 1, + ]); + + for ($p = 1; $p <= 4; $p++) { + $imagePath = 'products/product-'.$category->id.'-'.$p.'.jpg'; + $this->generateDummyImage($imagePath, 800, 800, $categoryName.' '.$p); + + Product::create([ + 'category_id' => $category->id, + 'name' => 'Owadan '.Str::lower($categoryName).' modeli '.$p, + 'description' => 'Bu '.Str::lower($categoryName).' örän ýokary hilli we berk materialdan öndürilen. Öýüňize bezeg gatar.', + 'price' => rand(1000, 15000), + 'is_active' => true, + 'image' => $imagePath, + ]); + } + } + + $this->command->info('Seeding Collections & Items...'); + $collections = ['Tomus Kolleksiýasy', 'Täze Ýyl', 'Otag Bezegi']; + + foreach ($collections as $index => $collectionName) { + $collection = Collection::create([ + 'title' => $collectionName, + 'subtitle' => 'Aýratyn dizaýnlar', + 'order' => $index + 1, + 'is_active' => true, + ]); + + for ($i = 1; $i <= 3; $i++) { + $imagePath = 'collections/item-'.$collection->id.'-'.$i.'.jpg'; + $this->generateDummyImage($imagePath, 600, 800, 'Item '.$i); + + CollectionItem::create([ + 'collection_id' => $collection->id, + 'title' => $collectionName.' elementi '.$i, + 'subtitle' => 'Gözel dizaýn '.$i, + 'order' => $i, + 'is_active' => true, + 'image' => $imagePath, + ]); + } + } + } + + private function generateDummyImage(string $path, int $width, int $height, string $text): void + { + // Try to download a random image from picsum, if it fails, generate a basic image using GD + try { + // Using UI Avatars for reliable and fast text-based placeholders + $url = 'https://ui-avatars.com/api/?name='.urlencode($text).'&size=512&background=random&color=fff&font-size=0.33'; + $contents = file_get_contents($url); + if ($contents) { + Storage::disk('public')->put($path, $contents); + + return; + } + } catch (\Exception $e) { + // fallback + } + + // GD fallback if network fails + if (extension_loaded('gd')) { + $image = imagecreatetruecolor($width, $height); + $bg = imagecolorallocate($image, rand(100, 200), rand(100, 200), rand(100, 200)); + $textColor = imagecolorallocate($image, 255, 255, 255); + imagefill($image, 0, 0, $bg); + imagestring($image, 5, $width / 2 - strlen($text) * 4, $height / 2 - 8, $text, $textColor); + + ob_start(); + imagejpeg($image); + $contents = ob_get_clean(); + imagedestroy($image); + + Storage::disk('public')->put($path, $contents); + } else { + // If GD is not available and download failed, just put an empty file or dummy svg + $svg = ''; + Storage::disk('public')->put($path, $svg); + } + } +} diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index e13bfe1..9ef8de2 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -57,7 +57,7 @@