create multiple rows in repeater when select option is changed

when I fetch all the warehouse products with the selected mark_id i want fill each product a new row in the repeater?
->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\Select::make('mark_id')
->label('Mark')
->reactive()
->options(Mark::all()->pluck('name', 'id'))->required()->searchable()->reactive()
])->columns(2),

Forms\Components\Card::make()
->schema([
Forms\Components\Grid::make(3)
->reactive()
->schema([
Forms\Components\Repeater::make('products')->columnSpan('full')
->schema(function (\Closure $get) {
if ($get('mark_id') == null) {
return [Forms\Components\Placeholder::make('')->content('Please Select Product')];
}
$warehouses = WarehouseProducts::where('mark_id', '=', $get('mark_id'))->get();
$fields = [];
foreach ($warehouses as $warehouse) {
array_push($fields, Forms\Components\Placeholder::make('product_name')
->label('Prodeuct Name')
->content($warehouse->product_name));
}
return $fields;
}
)
]),
]),
]);
->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\Select::make('mark_id')
->label('Mark')
->reactive()
->options(Mark::all()->pluck('name', 'id'))->required()->searchable()->reactive()
])->columns(2),

Forms\Components\Card::make()
->schema([
Forms\Components\Grid::make(3)
->reactive()
->schema([
Forms\Components\Repeater::make('products')->columnSpan('full')
->schema(function (\Closure $get) {
if ($get('mark_id') == null) {
return [Forms\Components\Placeholder::make('')->content('Please Select Product')];
}
$warehouses = WarehouseProducts::where('mark_id', '=', $get('mark_id'))->get();
$fields = [];
foreach ($warehouses as $warehouse) {
array_push($fields, Forms\Components\Placeholder::make('product_name')
->label('Prodeuct Name')
->content($warehouse->product_name));
}
return $fields;
}
)
]),
]),
]);
`
0 Replies
No replies yetBe the first to reply to this messageJoin