MultipleImage.php 935 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. use Dcat\Admin\Support\Helper;
  4. class MultipleImage extends Image
  5. {
  6. protected $view = 'admin::form.file';
  7. /**
  8. * Set a limit of files.
  9. *
  10. * @param int $limit
  11. *
  12. * @return $this
  13. */
  14. public function limit(int $limit)
  15. {
  16. if ($limit < 2) {
  17. return $this;
  18. }
  19. $this->options['fileNumLimit'] = $limit;
  20. return $this;
  21. }
  22. /**
  23. * Prepare for saving.
  24. *
  25. * @param string|array $file
  26. *
  27. * @return array
  28. */
  29. protected function prepareToSave($file)
  30. {
  31. if ($path = request(static::FILE_DELETE_FLAG)) {
  32. $this->deleteFile($path);
  33. return array_diff($this->original, [$path]);
  34. }
  35. $file = Helper::array($file, true);
  36. $this->destroyIfChanged($file);
  37. return $file;
  38. }
  39. protected function forceOptions()
  40. {
  41. }
  42. }