F
Filament14mo ago
Bloom

Using query builder on Hint or helperText

Is there a way to display query on Hint or heloperText. I want to display the available quantity when i select the item. Or is there another way to do it . : Forms\Components\Select::make('item_id') ->options(Item::query()->pluck('item_name', 'id')) ->reactive() ->afterStateUpdated(fn(callable $set) => $set('quantity', null)) ->required(), Forms\Components\TextInput::make('quantity') ->helperText(fn(callable $get)=>MainStock::query()->pluck('quantity')->whereIn('item_id',$get('item_id')))
2 Replies
Hemith
Hemith14mo ago
Select::make('product_id')
->live()
->required()
->relationship('product', 'name')
->searchable(),
TextInput::make('quantity')
->required()
->live()
->hint(function (Get $get) {
$productId = $get('product_id');
if ($productId) {
// Run query to get quantity and return
}

return null;
})
->integer()
Select::make('product_id')
->live()
->required()
->relationship('product', 'name')
->searchable(),
TextInput::make('quantity')
->required()
->live()
->hint(function (Get $get) {
$productId = $get('product_id');
if ($productId) {
// Run query to get quantity and return
}

return null;
})
->integer()
This is how I did it for my project. The hint function grabs the product_id whenever the select option change and run the query. Maybe this will help.
Bloom
BloomOP14mo ago
thank you i will try that
Want results from more Discord servers?
Add your server