src/Models/Database/Product.php
public function saveProductImages(array $data):self
    {
        if (isset($data['image']) && count($data['image']) > 0) {
            $exitingIds = $this->images()->get()->pluck('id')->toArray();
            foreach ($data['image'] as $key => $data) {
                if (is_int($key)) {
                    if (($findKey = array_search($key, $exitingIds)) !== false) {
                        $productImage = ProductImage::findorfail($key);
                        $productImage->update($data);
                        unset($exitingIds[$findKey]);
                    }
                    continue;
                }
                ProductImage::create($data + ['product_id' => $this->id]);
            }
            if (count($exitingIds) > 0) {
                ProductImage::destroy($exitingIds);
            }
        }
        return $this;
    }
public function saveProductImages(array $data):self
    {
        if (isset($data['image']) && count($data['image']) > 0) {
            $exitingIds = $this->images()->get()->pluck('id')->toArray();
            foreach ($data['image'] as $key => $data) {
                if (is_int($key)) {
                    if (($findKey = array_search($key, $exitingIds)) !== false) {
                        $productImage = ProductImage::findorfail($key);
                        $productImage->update($data);
                        unset($exitingIds[$findKey]);
                    }
                    continue;
                }
                ProductImage::create($data + ['product_id' => $this->id]);
            }
            if (count($exitingIds) > 0) {
                ProductImage::destroy($exitingIds);
            }
        }
        return $this;
    }
public function saveProductImages ( array $ data ) : self { if ( isset ( $ data [ 'image' ] ) && count ( $ data [ 'image' ] ) > 0 ) { $ exitingIds = $ this -> images ( ) -> get ( ) -> pluck ( 'id' ) -> toArray ( ) ; foreach ( $ data [ 'image' ] as $ key => $ data ) { if ( is_int ( $ key ) ) { if ( ( $ findKey = array_search ( $ key , $ exitingIds ) ) !== false ) { $ productImage = ProductImage :: findorfail ( $ key ) ; $ productImage -> update ( $ data ) ; unset ( $ exitingIds [ $ findKey ] ) ; } continue ; } ProductImage :: create ( $ data + [ 'product_id' => $ this -> id ] ) ; } if ( count ( $ exitingIds ) > 0 ) { ProductImage :: destroy ( $ exitingIds ) ; } } return $ this ; }
Save Product Images.

@param array $$data
@return \AvoRed\Framework\Models\Database\Product $this
Save Product Images .