Checkbox.php 760 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Dcat\Admin\Support\Helper;
  4. use Illuminate\Support\Arr;
  5. class Checkbox extends Radio
  6. {
  7. protected $view = 'admin::widgets.checkbox';
  8. protected $type = 'checkbox';
  9. protected $checked = [];
  10. /**
  11. * 设置选中的的选项.
  12. *
  13. * @param string|array $options
  14. *
  15. * @return $this
  16. */
  17. public function check($options)
  18. {
  19. $this->checked = Helper::array($options);
  20. return $this;
  21. }
  22. /**
  23. * 选中所有选项.
  24. *
  25. * @param string|array $excepts
  26. *
  27. * @return $this
  28. */
  29. public function checkAll($excepts = [])
  30. {
  31. return $this->check(
  32. array_keys(Arr::except($this->options, $excepts))
  33. );
  34. }
  35. }