Add + button next to select button in repeater conditionally
Hello, I am trying to add a + sign in my repeater when the value of the select-box is empty or when the record in the repeater is new.
At the moment not succeeding. This is my code. Do you have any suggestions?
At the moment not succeeding. This is my code. Do you have any suggestions?
return [
Select::make('product_id')
(.....)
//====>>>> This is the part of the code the question is about <<<<<============
->when(!filled('product'), function (Select $select) {
return $select
->relationship('product', 'description', function (Builder $query, Get $get) {
$query->where('brand_id', '=', $get('../../brand_id'));
})
->getOptionLabelFromRecordUsing(fn(Product $product): ?string => $product->description)
->createOptionForm(function (Get $get) {
return [
Hidden::make('brand_id')
->default($get('../../brand_id')),
Hidden::make('supplier_id')
->default($get('../../supplier_id')),
TextInput::make('item_code')
->label('Artikelcode')
->required()
->maxLength(255),
});
}),
];
); return [
Select::make('product_id')
(.....)
//====>>>> This is the part of the code the question is about <<<<<============
->when(!filled('product'), function (Select $select) {
return $select
->relationship('product', 'description', function (Builder $query, Get $get) {
$query->where('brand_id', '=', $get('../../brand_id'));
})
->getOptionLabelFromRecordUsing(fn(Product $product): ?string => $product->description)
->createOptionForm(function (Get $get) {
return [
Hidden::make('brand_id')
->default($get('../../brand_id')),
Hidden::make('supplier_id')
->default($get('../../supplier_id')),
TextInput::make('item_code')
->label('Artikelcode')
->required()
->maxLength(255),
});
}),
];
);