Code Duplication    Length = 9-9 lines in 2 locations

models/Discount.php 2 locations

@@ 218-226 (lines=9) @@
215
                $products = $products->merge($category->products);
216
            }
217
218
            foreach ($products as $product) {
219
                $data[] = [
220
                    'discount_id' => $discount->id,
221
                    'end_at' => $discount->end_at,
222
                    'price' => $discount->calculatePrice($product->base_price),
223
                    'product_id' => $product->id,
224
                    'start_at' => $discount->start_at,
225
                ];
226
            }
227
        }
228
229
        Price::whereNotNull('discount_id')->delete();
@@ 242-250 (lines=9) @@
239
            ->get();
240
241
        $data = [];
242
        foreach ($discounts as $discount) {
243
            $data[] = [
244
                'discount_id' => $discount->id,
245
                'end_at' => $discount->end_at,
246
                'price' => $discount->calculatePrice($product->base_price),
247
                'product_id' => $product->id,
248
                'start_at' => $discount->start_at,
249
            ];
250
        }
251
252
        Price::whereProductId($product->id)->whereIn('discount_id', $discounts->lists('id'))->delete();
253
        Price::insert($data);