wip
This commit is contained in:
44
nova-components/ProductInventory/src/ProductInventory.php
Normal file
44
nova-components/ProductInventory/src/ProductInventory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user