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(),

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


Thank you!
Was this page helpful?