|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Eclipse\Cms\Factories; |
| 4 | + |
| 5 | +use Eclipse\Cms\Models\Banner\Image; |
| 6 | +use Illuminate\Database\Eloquent\Factories\Factory; |
| 7 | + |
| 8 | +class BannerImageFactory extends Factory |
| 9 | +{ |
| 10 | + protected $model = Image::class; |
| 11 | + |
| 12 | + public function definition(): array |
| 13 | + { |
| 14 | + $sampleImages = [ |
| 15 | + 'banners/summer-sale-desktop.jpg', |
| 16 | + 'banners/winter-collection-mobile.jpg', |
| 17 | + 'banners/spring-deals-tablet.jpg', |
| 18 | + 'banners/black-friday-hero.jpg', |
| 19 | + 'banners/new-arrivals-sidebar.jpg', |
| 20 | + 'banners/limited-offer-footer.jpg', |
| 21 | + 'banners/featured-product-square.jpg', |
| 22 | + 'banners/special-promo-wide.jpg', |
| 23 | + 'banners/holiday-sale-banner.jpg', |
| 24 | + 'banners/end-season-deals.jpg', |
| 25 | + ]; |
| 26 | + |
| 27 | + return [ |
| 28 | + 'file' => $this->faker->randomElement($sampleImages), |
| 29 | + 'image_width' => $this->faker->randomElement([400, 800, 1200, 1920]), |
| 30 | + 'image_height' => $this->faker->randomElement([200, 400, 600, 800]), |
| 31 | + 'is_hidpi' => $this->faker->boolean(30), |
| 32 | + ]; |
| 33 | + } |
| 34 | + |
| 35 | + public function desktop(): static |
| 36 | + { |
| 37 | + return $this->state(fn (array $attributes): array => [ |
| 38 | + 'file' => 'banners/desktop-'.$this->faker->slug().'.jpg', |
| 39 | + 'image_width' => 1920, |
| 40 | + 'image_height' => 600, |
| 41 | + 'is_hidpi' => false, |
| 42 | + ]); |
| 43 | + } |
| 44 | + |
| 45 | + public function mobile(): static |
| 46 | + { |
| 47 | + return $this->state(fn (array $attributes): array => [ |
| 48 | + 'file' => 'banners/mobile-'.$this->faker->slug().'.jpg', |
| 49 | + 'image_width' => 800, |
| 50 | + 'image_height' => 400, |
| 51 | + 'is_hidpi' => true, |
| 52 | + ]); |
| 53 | + } |
| 54 | + |
| 55 | + public function tablet(): static |
| 56 | + { |
| 57 | + return $this->state(fn (array $attributes): array => [ |
| 58 | + 'file' => 'banners/tablet-'.$this->faker->slug().'.jpg', |
| 59 | + 'image_width' => 1024, |
| 60 | + 'image_height' => 500, |
| 61 | + 'is_hidpi' => false, |
| 62 | + ]); |
| 63 | + } |
| 64 | + |
| 65 | + public function square(): static |
| 66 | + { |
| 67 | + return $this->state(fn (array $attributes): array => [ |
| 68 | + 'file' => 'banners/square-'.$this->faker->slug().'.jpg', |
| 69 | + 'image_width' => 400, |
| 70 | + 'image_height' => 400, |
| 71 | + 'is_hidpi' => false, |
| 72 | + ]); |
| 73 | + } |
| 74 | + |
| 75 | + public function hidpi(): static |
| 76 | + { |
| 77 | + return $this->state(fn (array $attributes): array => [ |
| 78 | + 'is_hidpi' => true, |
| 79 | + 'image_width' => $attributes['image_width'] * 2, |
| 80 | + 'image_height' => $attributes['image_height'] * 2, |
| 81 | + ]); |
| 82 | + } |
| 83 | +} |
0 commit comments