@@ 7-32 (lines=26) @@ | ||
4 | ||
5 | use Sco\Admin\Traits\HasSelectOptions; |
|
6 | ||
7 | class Select extends Filter |
|
8 | { |
|
9 | use HasSelectOptions; |
|
10 | ||
11 | protected $type = 'select'; |
|
12 | ||
13 | protected $options; |
|
14 | ||
15 | protected $defaultValue = ''; |
|
16 | ||
17 | public function __construct($name, $title, $options = null) |
|
18 | { |
|
19 | parent::__construct($name, $title); |
|
20 | ||
21 | if (! is_null($options)) { |
|
22 | $this->setOptions($options); |
|
23 | } |
|
24 | } |
|
25 | ||
26 | public function toArray() |
|
27 | { |
|
28 | return parent::toArray() + [ |
|
29 | 'options' => $this->getOptions(), |
|
30 | ]; |
|
31 | } |
|
32 | } |
|
33 |
@@ 8-38 (lines=31) @@ | ||
5 | use Illuminate\Database\Eloquent\Model; |
|
6 | use Sco\Admin\Traits\HasSelectOptions; |
|
7 | ||
8 | class Select extends NamedElement |
|
9 | { |
|
10 | use HasSelectOptions; |
|
11 | ||
12 | protected $type = 'select'; |
|
13 | ||
14 | protected $cast = 'string'; |
|
15 | ||
16 | ||
17 | /** |
|
18 | * |
|
19 | * @param string $name |
|
20 | * @param string $title |
|
21 | * @param array|Model $options |
|
22 | */ |
|
23 | public function __construct(string $name, string $title, $options = null) |
|
24 | { |
|
25 | parent::__construct($name, $title); |
|
26 | ||
27 | if (! is_null($options)) { |
|
28 | $this->setOptions($options); |
|
29 | } |
|
30 | } |
|
31 | ||
32 | public function toArray() |
|
33 | { |
|
34 | return parent::toArray() + [ |
|
35 | 'options' => $this->getOptions(), |
|
36 | ]; |
|
37 | } |
|
38 | } |
|
39 |