| Total Complexity | 7 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class FormSelect extends Component |
||
| 10 | { |
||
| 11 | use HandlesValidationErrors; |
||
| 12 | use HandlesBoundValues; |
||
| 13 | |||
| 14 | public string $name; |
||
| 15 | public string $label; |
||
| 16 | public $options; |
||
| 17 | public $selectedKey; |
||
| 18 | public bool $multiple; |
||
| 19 | public bool $floating; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Create a new component instance. |
||
| 23 | * |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | public function __construct( |
||
| 27 | string $name, |
||
| 28 | string $label = '', |
||
| 29 | $options = [], |
||
| 30 | $bind = null, |
||
| 31 | $default = null, |
||
| 32 | bool $multiple = false, |
||
| 33 | bool $showErrors = true, |
||
| 34 | bool $manyRelation = false, |
||
| 35 | bool $floating = false |
||
| 36 | ) { |
||
| 37 | $this->name = $name; |
||
| 38 | $this->label = $label; |
||
| 39 | $this->options = $options; |
||
| 40 | $this->manyRelation = $manyRelation; |
||
| 41 | |||
| 42 | if ($this->isNotWired()) { |
||
| 43 | $inputName = Str::before($name, '[]'); |
||
| 44 | |||
| 45 | $default = $this->getBoundValue($bind, $inputName) ?: $default; |
||
| 46 | |||
| 47 | $this->selectedKey = old(static::convertBracketsToDots($inputName), $default); |
||
| 48 | |||
| 49 | if ($this->selectedKey instanceof Arrayable) { |
||
| 50 | $this->selectedKey = $this->selectedKey->toArray(); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | $this->multiple = $multiple; |
||
| 55 | $this->showErrors = $showErrors; |
||
| 56 | $this->floating = $floating && !$multiple; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function isSelected($key): bool |
||
| 66 | } |
||
| 67 | } |
||
| 68 |