Checkbox.php 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. *
  13. * @return $this
  14. */
  15. public function checked($id)
  16. {
  17. $this->checked = (array) $id;
  18. return $this;
  19. }
  20. /**
  21. * @param $excepts
  22. *
  23. * @return Checkbox
  24. */
  25. public function checkedAll($excepts = [])
  26. {
  27. return $this->checked(array_keys(Arr::except($this->options, $excepts)));
  28. }
  29. public function circle(bool $flag)
  30. {
  31. $this->circle = $flag;
  32. return $this;
  33. }
  34. public function square()
  35. {
  36. return $this->circle(false);
  37. }
  38. public function variables()
  39. {
  40. $v = parent::variables();
  41. $v['circle'] = $this->circle ? 'checkbox-circle' : '';
  42. return $v;
  43. }
  44. }