diff --git a/src/Models/Product.php b/src/Models/Product.php index 77204566..a5b3971f 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -203,7 +203,7 @@ public function getUrlAttribute(): string public function getImagesAttribute(): array { - return $this->gallery->pluck('value')->toArray(); + return $this->gallery->sortBy('productImageValue.position')->pluck('value')->toArray(); } public function getImageAttribute($image): ?string diff --git a/src/Models/ProductImage.php b/src/Models/ProductImage.php index fce7c075..0443c057 100644 --- a/src/Models/ProductImage.php +++ b/src/Models/ProductImage.php @@ -10,6 +10,8 @@ class ProductImage extends Model protected $primaryKey = 'value_id'; + protected $with = ['productImageValue']; + protected static function booted(): void { static::addGlobalScope(