public static ?Model $productType = null;
public static function getOptionsFormComponents(): array
{
return [
// If this is set to "live" the sample file provided by the action
// will contain no columns
Select::make('product')
->required()
->hidden(fn (Get $get) => $get('file'))
->options(fn () => ProductType::pluck('name', 'id'))
->afterStateUpdated(function (Set $set, $state) {
self::$productType = ProductType::with(['mappedAttributes'])->find($state);
$set('product_file', $state);
}),
// This needs to be "live", otherwise when you upload the file and change this field
// the mapping columns don't show up on the modal form
Select::make('product_file')
->required()
->hidden(fn (Get $get) => !$get('file'))
->live()
->options(fn () => ProductType::pluck('name', 'id'))
->afterStateUpdated(function ($state) {
self::$productType = ProductType::with(['mappedAttributes'])->find($state);
}),
];
}
public static function getColumns(): array
{
return self::$productType?->mappedAttributes->pluck('name.en')->map(fn ($name) => ImportColumn::make($name))->toArray() ?? [];
}
public static ?Model $productType = null;
public static function getOptionsFormComponents(): array
{
return [
// If this is set to "live" the sample file provided by the action
// will contain no columns
Select::make('product')
->required()
->hidden(fn (Get $get) => $get('file'))
->options(fn () => ProductType::pluck('name', 'id'))
->afterStateUpdated(function (Set $set, $state) {
self::$productType = ProductType::with(['mappedAttributes'])->find($state);
$set('product_file', $state);
}),
// This needs to be "live", otherwise when you upload the file and change this field
// the mapping columns don't show up on the modal form
Select::make('product_file')
->required()
->hidden(fn (Get $get) => !$get('file'))
->live()
->options(fn () => ProductType::pluck('name', 'id'))
->afterStateUpdated(function ($state) {
self::$productType = ProductType::with(['mappedAttributes'])->find($state);
}),
];
}
public static function getColumns(): array
{
return self::$productType?->mappedAttributes->pluck('name.en')->map(fn ($name) => ImportColumn::make($name))->toArray() ?? [];
}