FilamentF
Filament3y ago
Abi

Binding TextColumn with a BelongsToMany relation

How can I bind a TextColumn with a belongsToMany relation. Not sure if I am making a mistake. For a customer_orders, I have an addresses with a BelongsToMany relationship because a customer can have a billing and a shipping address. The customers name is stored on the address table and I want to show that on the Order resource on filament. How do I go about doing this? should I use a ViewColumn?

I tried this, will it work

TextColumn::make('customer_name')->formatStateUsing(function ($state, $record) {
                $shippingAddress = $record->shippingAddress->first();
                return $shippingAddress->first_name . ' ' . $shippingAddress->last_name;
            }),
Was this page helpful?