src/Hassansin/DBCart/Models/Cart.php
public function moveItemsTo(Cart $cart){

        \DB::transaction(function () use(&$cart){
            $current_items = $cart->items()->pluck('product_id');
            $items_to_move = $this->items()->whereNotIn('product_id', $current_items->toArray())->get();
            if($items_to_move->count() === 0){
                return;
            }
            $this->items()->whereNotIn('product_id', $current_items->toArray())->update([
                'cart_id' => $cart->id
            ]);
            foreach($items_to_move as $item) {
                $this->item_count -= $item->quantity;
                $this->total_price -= $item->getPrice();
                $cart->item_count += $item->quantity;
                $cart->total_price += $item->getPrice();
            }
            $this->relations = [];
            $cart->relations = [];
            $this->save();
            $cart->save();
        });
        return $cart;
    }
public function moveItemsTo(Cart $cart){

        \DB::transaction(function () use(&$cart){
            $current_items = $cart->items()->pluck('product_id');
            $items_to_move = $this->items()->whereNotIn('product_id', $current_items->toArray())->get();
            if($items_to_move->count() === 0){
                return;
            }
            $this->items()->whereNotIn('product_id', $current_items->toArray())->update([
                'cart_id' => $cart->id
            ]);
            foreach($items_to_move as $item) {
                $this->item_count -= $item->quantity;
                $this->total_price -= $item->getPrice();
                $cart->item_count += $item->quantity;
                $cart->total_price += $item->getPrice();
            }
            $this->relations = [];
            $cart->relations = [];
            $this->save();
            $cart->save();
        });
        return $cart;
    }
public function moveItemsTo ( Cart $ cart ) { \ DB :: transaction ( function ( ) use ( & $ cart ) { $ current_items = $ cart -> items ( ) -> pluck ( 'product_id' ) ; $ items_to_move = $ this -> items ( ) -> whereNotIn ( 'product_id' , $ current_items -> toArray ( ) ) -> get ( ) ; if ( $ items_to_move -> count ( ) === 0 ) { return ; } $ this -> items ( ) -> whereNotIn ( 'product_id' , $ current_items -> toArray ( ) ) -> update ( [ 'cart_id' => $ cart -> id ] ) ; foreach ( $ items_to_move as $ item ) { $ this -> item_count -= $ item -> quantity ; $ this -> total_price -= $ item -> getPrice ( ) ; $ cart -> item_count += $ item -> quantity ; $ cart -> total_price += $ item -> getPrice ( ) ; } $ this -> relations = [ ] ; $ cart -> relations = [ ] ; $ this -> save ( ) ; $ cart -> save ( ) ; } ) ; return $ cart ; }
Move Items to another cart instance

@param Cart $cart
Move Items to another cart instance