ProductTaxService.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Services;
  3. use App\Models\ProductTax;
  4. class ProductTaxService
  5. {
  6. public function store(array $data)
  7. {
  8. $collection = collect($data);
  9. if ($collection['tax_id']) {
  10. foreach ($collection['tax_id'] as $key => $val) {
  11. $product_tax = new ProductTax();
  12. $product_tax->tax_id = $val;
  13. $product_tax->product_id = $collection['product_id'];
  14. $product_tax->tax = $collection['tax'][$key];
  15. $product_tax->tax_type = $collection['tax_type'][$key];
  16. $product_tax->save();
  17. }
  18. }
  19. }
  20. public function product_duplicate_store($product_taxes , $product_new)
  21. {
  22. foreach ($product_taxes as $key => $tax) {
  23. $product_tax = new ProductTax;
  24. $product_tax->product_id = $product_new->id;
  25. $product_tax->tax_id = $tax->tax_id;
  26. $product_tax->tax = $tax->tax;
  27. $product_tax->tax_type = $tax->tax_type;
  28. $product_tax->save();
  29. }
  30. }
  31. }