45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Nurmuhammet\ProductInventory;
|
|
|
|
use Illuminate\Support\Collection;
|
|
use Laravel\Nova\Fields\Field;
|
|
use Laravel\Nova\Fields\SupportsDependentFields;
|
|
|
|
class ProductInventory extends Field
|
|
{
|
|
use SupportsDependentFields;
|
|
|
|
/**
|
|
* The field's component.
|
|
*
|
|
* @var string
|
|
*/
|
|
public $component = 'product-inventory';
|
|
|
|
/**
|
|
* Set the options for the select menu.
|
|
*
|
|
* @param array<string|int, array<string, mixed>|string>|\Closure|callable|\Illuminate\Support\Collection $options
|
|
* @return $this
|
|
*
|
|
* @phpstan-param TOption|(callable(): (TOption))|(\Closure(): (TOption)) $options
|
|
*/
|
|
public function options(array|Collection $options): self
|
|
{
|
|
return $this->withMeta([
|
|
'options' => $this->serializeOptions($options),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Serialize Options
|
|
*
|
|
* @param Collection $options
|
|
*/
|
|
public function serializeOptions(array|Collection $options): array|Collection
|
|
{
|
|
return collect($options)->map(fn ($label, $value) => ['label' => $label, 'value' => $value]);
|
|
}
|
|
}
|