© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
7 replies
KodyXgen

Call to undefined method BelongsToThrough::associate()

Hi,
I am new here so sorry if i don't do all the steps right.
I have 3 models, City, Zone, Country

A city belongs to a zone and a zone belongs to a country

I am trying to create a city add form since Laravel is not offering support for BelongsToThrough i pulled in the staudenmeir/belongs-to-through (as recomandate in Filamentphp documentation).

All is ok on view and list, but on update and create i have this error Znck\Eloquent\Relations\BelongsToThrough::associate(), and this is normal since the BelongsToThrough dosen't have the associate() function on it.

my form has this inputs/selects:

Select::make('country_id')
    ->label(__('country_name'))
    ->relationship('country', 'name')
    ->options(Country::all()->pluck('name', 'id')->toArray())
    ->reactive()
    ->rules('required')
    ->afterStateUpdated(fn (callable $set) => $set('zone_id', null)),

Select::make('zone_id')
    ->label(__('zone_name'))
    ->relationship('zone', 'name')
    ->options(function (callable $get) {
        $country = Country::find($get('country_id'));
        if (!$country) {
            return [];
        }
        return $country->zones->pluck('name', 'id');
    })
    ->rules('required'),

 TextInput::make('name')
        ->label(__('city.name'))
        ->rules('required|min:3|max:255')
        ->placeholder(__('city.name'))
        ->columnSpanFull(),
Select::make('country_id')
    ->label(__('country_name'))
    ->relationship('country', 'name')
    ->options(Country::all()->pluck('name', 'id')->toArray())
    ->reactive()
    ->rules('required')
    ->afterStateUpdated(fn (callable $set) => $set('zone_id', null)),

Select::make('zone_id')
    ->label(__('zone_name'))
    ->relationship('zone', 'name')
    ->options(function (callable $get) {
        $country = Country::find($get('country_id'));
        if (!$country) {
            return [];
        }
        return $country->zones->pluck('name', 'id');
    })
    ->rules('required'),

 TextInput::make('name')
        ->label(__('city.name'))
        ->rules('required|min:3|max:255')
        ->placeholder(__('city.name'))
        ->columnSpanFull(),

Has anyone run into this problem ? How did you fix it ?


Thank you!
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

Filament Resource Create/Edit BadMethodCallException Call to undefined method HasMany::associate()
FilamentFFilament / ❓┊help
3y ago
Call to undefined method Staudenmeir
FilamentFFilament / ❓┊help
3y ago
RelationManager Call to undefined method HasMany::getQualifiedRelatedKeyName
FilamentFFilament / ❓┊help
2y ago
Call to undefined method Filament\FilamentManager::getFontWeights()
FilamentFFilament / ❓┊help
3y ago