Поле Select включает все базовые методы.
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
];
}
//...

Вы можете использовать метод default()
, если вам нужно указать значение по умолчанию для поля.
default(mixed $default)
default(mixed $default)
default(mixed $default)
default(mixed $default)
default(mixed $default)
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->default('value 2')
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->default('value 2')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->default('value 2')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->default('value 2')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->default('value 2')
];
}
//...
Как и для всех полей, если вам нужно хранить NULL, необходимо добавить метод nullable()
.
nullable(Closure|bool|null $condition = null)
nullable(Closure|bool|null $condition = null)
nullable(Closure|bool|null $condition = null)
nullable(Closure|bool|null $condition = null)
nullable(Closure|bool|null $condition = null)
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->nullable()
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->nullable()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->nullable()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->nullable()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->nullable()
];
}
//...

Метод placeholder()
позволяет установить атрибут placeholder для поля.
placeholder(string $value)
placeholder(string $value)
placeholder(string $value)
placeholder(string $value)
placeholder(string $value)
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country')
->nullable()
->placeholder('Country')
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country')
->nullable()
->placeholder('Country')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country')
->nullable()
->placeholder('Country')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country')
->nullable()
->placeholder('Country')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country')
->nullable()
->placeholder('Country')
];
}
//...
Вы можете объединять значения в группы.
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('City', 'city_id')
->options([
'Italy' => [
1 => 'Rome',
2 => 'Milan'
],
'France' => [
3 => 'Paris',
4 => 'Marseille'
]
])
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('City', 'city_id')
->options([
'Italy' => [
1 => 'Rome',
2 => 'Milan'
],
'France' => [
3 => 'Paris',
4 => 'Marseille'
]
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('City', 'city_id')
->options([
'Italy' => [
1 => 'Rome',
2 => 'Milan'
],
'France' => [
3 => 'Paris',
4 => 'Marseille'
]
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('City', 'city_id')
->options([
'Italy' => [
1 => 'Rome',
2 => 'Milan'
],
'France' => [
3 => 'Paris',
4 => 'Marseille'
]
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('City', 'city_id')
->options([
'Italy' => [
1 => 'Rome',
2 => 'Milan'
],
'France' => [
3 => 'Paris',
4 => 'Marseille'
]
])
];
}
//...

Для выбора нескольких значений нужен метод multiple()
.
multiple(Closure|bool|null $condition = null)
multiple(Closure|bool|null $condition = null)
multiple(Closure|bool|null $condition = null)
multiple(Closure|bool|null $condition = null)
multiple(Closure|bool|null $condition = null)
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->multiple()
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->multiple()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->multiple()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->multiple()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->multiple()
];
}
//...
При использовании multiple()
для модели Eloquent требуется поле в базе данных типа text или json.
Также необходимо добавить cast - json или array или collection.

Если вам нужно добавить поиск среди значений, то необходимо добавить метод searchable()
.
searchable()
searchable()
searchable()
searchable()
searchable()
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
];
}
//...

Вы также можете организовать асинхронный поиск для поля Select. Для этого нужно передать url в метод async()
, на который будет отправлен запрос с параметром поиска query.
async(?string $asyncUrl = null)
async(?string $asyncUrl = null)
async(?string $asyncUrl = null)
async(?string $asyncUrl = null)
async(?string $asyncUrl = null)
Возвращаемый ответ с результатами поиска должен быть в формате json.
[
{
"value": 1,
"label": "Option 1"
},
{
"value": 2,
"label": "Option 2"
}
]
[
{
"value": 1,
"label": "Option 1"
},
{
"value": 2,
"label": "Option 2"
}
]
[
{
"value": 1,
"label": "Option 1"
},
{
"value": 2,
"label": "Option 2"
}
]
[
{
"value": 1,
"label": "Option 1"
},
{
"value": 2,
"label": "Option 2"
}
]
[
{
"value": 1,
"label": "Option 1"
},
{
"value": 2,
"label": "Option 2"
}
]
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
->async('/search')
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
->async('/search')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
->async('/search')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
->async('/search')
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
'value 1' => 'Option Label 1',
'value 2' => 'Option Label 2'
])
->searchable()
->async('/search')
];
}
//...
Метод updateOnPreview()
позволяет редактировать поле Select в режиме предпросмотра.
updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
updateOnPreview(?Closure $url = null, ?ResourceContract $resource = null, mixed $condition = null)
-$url
- url для обработки асинхронного запроса,
-$resource
- ресурс модели, на который ссылается отношение,
-$condition
- условие выполнения метода.
Настройки не обязательны и должны быть переданы, если поле работает вне ресурса.
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make(Country)
->updateOnPreview()
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make(Country)
->updateOnPreview()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make(Country)
->updateOnPreview()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make(Country)
->updateOnPreview()
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make(Country)
->updateOnPreview()
];
}
//...
Метод optionProperties()
позволяет добавить изображение к значению.
optionProperties(Closure|array $data)
optionProperties(Closure|array $data)
optionProperties(Closure|array $data)
optionProperties(Closure|array $data)
optionProperties(Closure|array $data)
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
])->optionProperties(fn() => [
1 => ['image' => '/images/ad.png'],
2 => ['image' => '/images/ae.png'],
])
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->optionProperties(fn() => [
1 => ['image' => '/images/ad.png'],
2 => ['image' => '/images/ae.png'],
//...
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->optionProperties(fn() => [
1 => ['image' => '/images/ad.png'],
2 => ['image' => '/images/ae.png'],
//...
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->optionProperties(fn() => [
1 => ['image' => '/images/ad.png'],
2 => ['image' => '/images/ae.png'],
//...
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->optionProperties(fn() => [
1 => ['image' => '/images/ad.png'],
2 => ['image' => '/images/ae.png'],
//...
])
];
}
//...

Все опции выбора доступны для изменения через data-атрибуты:
use MoonShine\Fields\Select;
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
])->customAttributes([
'data-max-item-count' => 2
])
];
}
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->customAttributes([
'data-max-item-count' => 2
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->customAttributes([
'data-max-item-count' => 2
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->customAttributes([
'data-max-item-count' => 2
])
];
}
//...
use MoonShine\Fields\Select;
//...
public function fields(): array
{
return [
Select::make('Country', 'country_id')
->options([
1 => 'Andorra',
2 => 'United Arab Emirates',
//...
])->customAttributes([
'data-max-item-count' => 2
])
];
}
//...
Для более подробной информации обратитесь к Choices.
Метод native()
отключает библиотеку Choices.js и отображает select в нативном режиме.
Select::make('Type')->native()
Select::make('Type')->native()
Select::make('Type')->native()
Select::make('Type')->native()
Select::make('Type')->native()