© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
AngryTestie

Retrieve data in pivot table many to many relationship

So I have two models Location and Company with many to many relationship, I want to get all the locations related to the company and the current_company_id of the auth user.

Here is the relationship that I'm using.

public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->using(CompanyLocation::class)
->wherePivot('company_id', auth()->user()->current_company_id);
}

This is where I want to get all the locations:

Forms\Components\Select::make('location')
->label('Location')
->multiple()
->relationship('locations','location_name')
->preload()
->createOptionForm([
Forms\Components\TextInput::make('location_name')
->required(),
]),

Here is what I'm getting it seems like it is selecting the locations table and not the pivot table.
image.png
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

Pivot column in many to many relationship - form builder
FilamentFFilament / ❓┊help
3y ago
Form field in relationship to pivot table
FilamentFFilament / ❓┊help
3y ago
🧩 How to Use reorderable() with Pivot Table Columns in Many-to-Many Relationships?
FilamentFFilament / ❓┊help
9mo ago