MultipleFile.php 1.1 KB

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