F
Filamentβ€’2y ago
astronomic

How can I create a virtual column with a name field from another table

I need to create a virtual column (or something similar) that concatenates the name of the product (products table) with the color of the product variant (product_variants table). The virtual column would be in the variant table. Is there any way to do it?
8 Replies
astronomic
astronomicOPβ€’2y ago
How can I do it with a Laravel 9 accesor? I try but it gives me an error. this is my code Forms\Components\Select::make('product_variant_id') ->label('Producto') ->required() ->searchable() ->options(ProductVariant::take(20)->pluck('full_name_product', 'id')) ->required() ->columnSpan(3),
Husky110
Husky110β€’2y ago
I'm kind of doing the same thing. I think your options()-call is wrong. Try this:
->options(fn() => ProductVariant::take(20)->pluck('full_name_product', 'id'))
->options(fn() => ProductVariant::take(20)->pluck('full_name_product', 'id'))
astronomic
astronomicOPβ€’2y ago
Thank you! but it always worked for me like this. I have discovered that without the get(), it does not work for me, now it does: ->options(ProductVariant::get()->pluck('full_name', 'id'))
Husky110
Husky110β€’2y ago
That's cause ->get gives you a Collection, ->pluck on a Collection gives you an array. ->options expects either an array or a closure.
->options(fn() => ProductVariant::take(20)->pluck('full_name_product', 'id'))
->options(fn() => ProductVariant::take(20)->pluck('full_name_product', 'id'))
is basically the same as
->options(
function () {
return ProductVariant::take(20)->pluck('full_name_product', 'id');
}
)
->options(
function () {
return ProductVariant::take(20)->pluck('full_name_product', 'id');
}
)
astronomic
astronomicOPβ€’2y ago
Ahh ok, I undertand, thank you so much!!
Husky110
Husky110β€’2y ago
Try playing arround with some of those anonymous functions. Filament can do some pretty funky stuff with those. πŸ™‚ See where you can pass a Closure and go for it.
astronomic
astronomicOPβ€’2y ago
hahaha, I'll listen to you, thank you very much once again 😊
Husky110
Husky110β€’2y ago
be my guest. πŸ™‚ I'm just startin to get the ropes of filament myself tho. πŸ˜„
Want results from more Discord servers?
Add your server