Frederick Osei
Frederick Osei

Reputation: 21

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

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?

Upvotes: 1

Views: 784

Answers (1)

Rose Riyadh
Rose Riyadh

Reputation: 668

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

enter image description here

enter image description here

Upvotes: 0

Related Questions