Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsToMany::getOwnerKeyName()

274 Views Asked by At

Am creating a Laravel Filament application. I have Services and Offices tables. I tried creating a many-to-many relationship using office_service table. I keep getting this error Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsToMany::getOwnerKeyName() when i use that relationship in my ServiceResource

This is my migration

public function up(): void
    {
        Schema::create('office_service', function (Blueprint $table) {
            $table->unsignedBigInteger('office_id')->nullable();
            $table->unsignedBigInteger('service_id')->nullable();
        });
    }

On my Service Model

public function offices()
    {
return $this->belongsToMany(Office::class, 'office_service');
    }

On my Office Model

 public function services()
    {
        return $this->belongsToMany(Service::class, 'office_service');
    }

On my filament ServiceResource this is what I have

Select::make('offices')
     ->relationship('offices', 'name')
    ->preload()
     ->searchable()
   ->columnSpan(2),

What am I not doing right?

1

There are 1 best solutions below

0
On

you need to add it in the following form to be working

enter image description here

enter image description here