F
Filament13mo ago
brahim

select options

->visible((fn (Get $get): array => bool ($get('product_id')) {[4 => "test"]}) can someone help me in this code
Solution:
->visible(fn (Get $get) => Product::find((int)$get('product_id'))?->name === 'Product Name')
->visible(fn (Get $get) => Product::find((int)$get('product_id'))?->name === 'Product Name')
...
Jump to solution
11 Replies
ConnorHowell
ConnorHowell13mo ago
What are you actually trying to achieve here?
toeknee
toeknee13mo ago
Sorry our mind reading skills are not quite there right now, please provide context as per the #✅┊rules of what you want this code to do as right not, it's meaingless code.
brahim
brahimOP13mo ago
i want make hide or visible a field and a select field
ConnorHowell
ConnorHowell13mo ago
Under what condition? Your current callback makes no sense. Share more of the code and explain the circumstances that you want the field to be hidden under
brahim
brahimOP13mo ago
Ok i will share with you code Select::make('product_id') ->label('Product') ->options(function (callable $get){ $subcategorie = SubCategory::find($get('sub_category_id')); if(!$subcategorie){ return Product::all()->pluck('name', 'id'); } return $subcategorie->Product->pluck('name', 'id'); }) ->required() ->preload() ->searchable() ->live() ->reactive() ->loadingMessage('Loading Produits...') ->noSearchResultsMessage('Pas de produit trouvé') ->placeholder('Sous Catégorie'),


TextInput::make('company_name') ->visible((fn (Get $get): array => bool ($get('product_id')) {[4 => "test"]}) thats my code
ConnorHowell
ConnorHowell13mo ago
So are you trying to hide the company_name field when product_id is 4? When should company_name be hidden/visible
brahim
brahimOP13mo ago
yes right but its select field and when i make value return null
ConnorHowell
ConnorHowell13mo ago
Then this will work, this will hide the company_name field when product_id is 4:
->visible(fn (Get $get) => $get('product_id') == 4)
->visible(fn (Get $get) => $get('product_id') == 4)
brahim
brahimOP13mo ago
its works thank you so much but i need make name of product not the ID is it possible really thank you for your help
Solution
toeknee
toeknee13mo ago
->visible(fn (Get $get) => Product::find((int)$get('product_id'))?->name === 'Product Name')
->visible(fn (Get $get) => Product::find((int)$get('product_id'))?->name === 'Product Name')
brahim
brahimOP13mo ago
thank you so much guys
Want results from more Discord servers?
Add your server