F
Filament5mo ago
Tazeen

Unable to Fetch Products Based on Selected Seller in Filament Form in Repeater

I'm trying to create a request form in a Filament resource where the user selects a seller and then selects products that belong to that seller. Despite using state management with hidden fields and afterStateUpdated callbacks to update and propagate the selected_seller_id, I'm unable to dynamically fetch and display the products associated with the selected seller in the Repeater field. Any help or alternative solutions would be greatly appreciated!
2 Replies
Tazeen
TazeenOP5mo ago
Select::make('seller_id') ->options(fn() => User::where('role_id', 3)->pluck('first_name', 'id')) ->required() ->label('Seller') ->searchable() ->preload() ->native(false) ->afterStateUpdated(function ($state, Set $set) { $set('selected_seller_id', $state); }), Hidden::make('selected_seller_id'), Repeater::make('products') ->schema([ Select::make('product_id') ->options(function (Get $get) { $sellerId = $get('selected_seller_id'); if ($sellerId) { $productIds = ProductUser::where('user_id', $sellerId)->pluck('product_id'); return Product::whereIn('id', $productIds)->pluck('name', 'id'); } return []; }) ->label('Product') ->preload() ->disableOptionsWhenSelectedInSiblingRepeaterItems() ->searchable(true) ->reactive() ->afterStateUpdated(function ($state, $set, $get) { $productId = $state; if ($productId) { $productUser = ProductUser::where('user_id', $get('selected_seller_id')) ->where('product_id', $productId) ->first(); if ($productUser) { $set('quantity_helper', "Minimum quantity is {$productUser->minimum_quantity}"); } else { $set('quantity_helper', "Select a valid product"); } } }), ]); This is the code that I am using
masthoni
masthoni5mo ago
Hi there, i have same problem with you. i tried to track the problem using debugbar and the problem are Get wont work on Select and $get('selected_seller_id') will return null regardless the updated value. if you solve this problem please let me know
Want results from more Discord servers?
Add your server