BaseProductImage.php 904 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Admin\Repositories;
  3. use App\Models\BaseProductImage as Model;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. use Carbon\Carbon;
  6. class BaseProductImage extends EloquentRepository
  7. {
  8. /**
  9. * Model.
  10. *
  11. * @var string
  12. */
  13. protected $eloquentClass = Model::class;
  14. public static function deleteByProductId($productId)
  15. {
  16. Model::where('product_id', $productId)->delete();
  17. }
  18. public static function saveProductImages($productId, $imageUrls)
  19. {
  20. // 准备数据集合
  21. $data = [];
  22. foreach ($imageUrls as $imageUrl) {
  23. $data[] = [
  24. 'product_id' => $productId,
  25. 'image_url' => $imageUrl,
  26. 'created_at' => Carbon::now(),
  27. 'updated_at' => Carbon::now(),
  28. ];
  29. }
  30. // 批量插入
  31. return Model::insert($data);
  32. }
  33. }