Select::modelName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\View\Components;
6
7
use Closure;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Support\Collection;
10
use Illuminate\View\Component;
11
12
class Select extends Component
13
{
14
    public string $uuid;
15
16
    public function __construct(
17
        public ?string $label = null,
18
        public ?string $icon = null,
19
        public ?string $iconRight = null,
20
        public ?string $hint = null,
21
        public ?string $hintClass = 'fieldset-label',
22
        public ?string $prefix = null,
23
        public ?string $suffix = null,
24
        public ?string $placeholder = null,
25
        public ?string $placeholderValue = null,
26
        public ?bool $inline = false,
27
        public ?string $optionValue = 'id',
28
        public ?string $optionLabel = 'name',
29
        public ?string $optionClass = '',
30
        public ?string $optionStyle = '',
31
        public Collection|array $options = new Collection(),
32
33
        // Slots
34
        public mixed $prepend = null,
35
        public mixed $append = null,
36
37
        // Validations
38
        public ?string $errorClass = 'text-error',
39
        public ?bool $omitError = false,
40
        public ?bool $firstErrorOnly = false,
41
    ) {
42
        $this->uuid = md5(serialize($this));
43
    }
44
45
    public function modelName(): ?string
46
    {
47
        return $this->attributes->whereStartsWith('wire:model')->first();
48
    }
49
50
    public function errorFieldName(): ?string
51
    {
52
        return $this->modelName() ?? $this->attributes->whereStartsWith('name')->first();
53
    }
54
55
    /**
56
     * Get the view / contents that represent the component.
57
     */
58
    public function render(): View|Closure|string
59
    {
60
        return view('components.select');
61
    }
62
}
63