Read data into repeater based on selected filed
there is a products table with mark_id if i chose the mark_id i want to fill all the products with the selected mark_id in my repeater and then save the repeater data in my packedProducts model using relationship please help me this is my code and screenshot.
Forms\Components\Select::make('mark_id')
->label('Mark')
->reactive()
->options(function () {
return Mark::whereHas('warehouse', function ($query) {
$query->where('status', 'delivered')
->whereHas('products', function ($query) {
$query->where('remaining_qty', '>', 0);
});
})->pluck('name', 'id');
})->searchable()->reactive(),
Forms\Components\Repeater::make('packed_products')
->relationship()
->reactive()
->schema(function (\Filament\Forms\Get $get) {
if (!$get('../mark_id')) {
return [Forms\Components\Placeholder::make('Select Mark First')];
}
[
Forms\Components\TextInput::make('product_name')
->required()->numeric()->reactive()->rules('numeric|gt:0')
Forms\Components\TextInput::make('quantity')
->required()->numeric()->reactive()->rules('numeric|gt:0')
Forms\Components\Placeholder::make('remaining_qty')->reactive()
];
}); Forms\Components\Select::make('mark_id')
->label('Mark')
->reactive()
->options(function () {
return Mark::whereHas('warehouse', function ($query) {
$query->where('status', 'delivered')
->whereHas('products', function ($query) {
$query->where('remaining_qty', '>', 0);
});
})->pluck('name', 'id');
})->searchable()->reactive(),
Forms\Components\Repeater::make('packed_products')
->relationship()
->reactive()
->schema(function (\Filament\Forms\Get $get) {
if (!$get('../mark_id')) {
return [Forms\Components\Placeholder::make('Select Mark First')];
}
[
Forms\Components\TextInput::make('product_name')
->required()->numeric()->reactive()->rules('numeric|gt:0')
Forms\Components\TextInput::make('quantity')
->required()->numeric()->reactive()->rules('numeric|gt:0')
Forms\Components\Placeholder::make('remaining_qty')->reactive()
];
});