MultipleImage.php 1.0 KB

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