Checkbox.php 959 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Dcat\Admin\Widgets;
  3. use Illuminate\Support\Arr;
  4. class Checkbox extends Radio
  5. {
  6. protected $view = 'admin::widgets.checkbox';
  7. protected $type = 'checkbox';
  8. protected $circle = true;
  9. protected $checked = [];
  10. /**
  11. * @param $id
  12. * @return $this
  13. */
  14. public function checked($id)
  15. {
  16. $this->checked = (array)$id;
  17. return $this;
  18. }
  19. /**
  20. * @param $excepts
  21. * @return Checkbox
  22. */
  23. public function checkedAll($excepts = [])
  24. {
  25. return $this->checked(array_keys(Arr::except($this->options, $excepts)));
  26. }
  27. public function circle(bool $flag)
  28. {
  29. $this->circle = $flag;
  30. return $this;
  31. }
  32. public function square()
  33. {
  34. return $this->circle(false);
  35. }
  36. public function variables()
  37. {
  38. $v = parent::variables();
  39. $v['circle'] = $this->circle ? 'checkbox-circle' : '';
  40. return $v;
  41. }
  42. }