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
ConnorHowell2y ago
What are you actually trying to achieve here?
toeknee
toeknee2y 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
brahimOP2y ago
i want make hide or visible a field and a select field
ConnorHowell
ConnorHowell2y 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
brahimOP2y 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
ConnorHowell2y ago
So are you trying to hide the company_name field when product_id is 4? When should company_name be hidden/visible
brahim
brahimOP2y ago
yes right but its select field and when i make value return null
ConnorHowell
ConnorHowell2y 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
brahimOP2y 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
toeknee2y 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
brahimOP2y ago
thank you so much guys

Did you find this page helpful?