© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago•
46 replies
Roland Barkóczi

How to manage ManyToMany relation in TableBuilder and FormBuilder?

I have the following models
Product
- id
- name

Pricelist
- id
- name

ProductPrice
- id
- product_id
- pricelist_id
- price

I want to create a dynamic table on product listing page, where all the Pricelist are listed as columns (e.g. Retail, Reseller, Discount) and respectively the belonging product prices.

I defined these functions in Product model:
    public function prices(): HasMany
    {
        return $this->hasMany(ProductPrice::class, 'product_id');
    }

    public function price($pricelist_id)
    {
        return $this->prices()->where('pricelist_id', $pricelist_id)->first();
    }
    public function prices(): HasMany
    {
        return $this->hasMany(ProductPrice::class, 'product_id');
    }

    public function price($pricelist_id)
    {
        return $this->prices()->where('pricelist_id', $pricelist_id)->first();
    }

Furthermore I tried this code in the ProductRelationsManager table columns function:
...array_map(
  fn(Pricelist $pricelist) => TextColumn::make('price_' . $pricelist->id)
->label($pricelist->name), $this->getOwnerRecord()->pricelists()->get()->all())
...array_map(
  fn(Pricelist $pricelist) => TextColumn::make('price_' . $pricelist->id)
->label($pricelist->name), $this->getOwnerRecord()->pricelists()->get()->all())

So it creates all the pricelist columns, but I have no clue what should I add to the TextColumn::make() parameter in order to reach the given price belonging to the actual pricelist.

Also have no clues how to define the form, what should I add to the TextInput::make() as parameter.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Component as row in TableBuilder
FilamentFFilament / ❓┊help
2y ago
How i disabled the clickable row in TableBuilder
FilamentFFilament / ❓┊help
3y ago
How to manage roles and permissions ?
FilamentFFilament / ❓┊help
3y ago
How to push JS for a custom field in the formbuilder
FilamentFFilament / ❓┊help
3y ago