Conditions | 7 |
Paths | 14 |
Total Lines | 32 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | public function __construct( |
||
25 | string $name, |
||
26 | string $label = '', |
||
27 | $value = 1, |
||
28 | $bind = null, |
||
29 | bool $default = false, |
||
30 | bool $showErrors = true |
||
31 | ) { |
||
32 | $this->name = $name; |
||
33 | $this->label = $label; |
||
34 | $this->value = $value; |
||
35 | $this->showErrors = $showErrors; |
||
36 | |||
37 | $inputName = Str::before($name, '[]'); |
||
38 | |||
39 | if ($oldData = old(static::convertBracketsToDots($inputName))) { |
||
40 | $this->checked = in_array($value, Arr::wrap($oldData)); |
||
41 | } |
||
42 | |||
43 | if (!session()->hasOldInput() && $this->isNotWired()) { |
||
44 | $boundValue = $this->getBoundValue($bind, $inputName); |
||
45 | |||
46 | if ($boundValue instanceof Arrayable) { |
||
47 | $boundValue = $boundValue->toArray(); |
||
48 | } |
||
49 | |||
50 | if (is_array($boundValue)) { |
||
51 | $this->checked = in_array($value, $boundValue); |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $this->checked = is_null($boundValue) ? $default : $boundValue; |
||
56 | } |
||
69 |