29 lines
777 B
PHP
29 lines
777 B
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
class Options
|
|
{
|
|
/**
|
|
* Turn a Blade style `[value => label]` list into select options.
|
|
*
|
|
* The repositories and enums still hand back keyed arrays, which a <select>
|
|
* cannot iterate in a stable order once it crosses into JSON.
|
|
*
|
|
* @param array<array-key, string>|Collection<array-key, string> $list
|
|
* @return array<int, array{value: string|int, label: string}>
|
|
*/
|
|
public static function fromList(array|Collection $list): array
|
|
{
|
|
return collect($list)
|
|
->map(fn (string $label, string|int $value) => [
|
|
'value' => $value,
|
|
'label' => $label,
|
|
])
|
|
->values()
|
|
->all();
|
|
}
|
|
}
|