调用未定义的方法 Illuminate\Database\Eloquent\Relations\BelongsToMany::getOwnerKeyName()

问题描述 投票:0回答:1

正在创建 Laravel Filament 应用程序。我有 ServicesOffices 表。我尝试使用 office_service 表创建多对多关系。当我在 ServiceResource 中使用该关系时,我不断收到此错误调用未定义的方法 Illuminate\Database\Eloquent\Relations\BelongsToMany::getOwnerKeyName()

这是我的迁移

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

我的服务模式

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

在我的办公室模型上

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

在我的灯丝服务资源上,这就是我所拥有的

Select::make('offices') ->relationship('offices', 'name') ->preload() ->searchable() ->columnSpan(2),
我哪里做得不对?

laravel eloquent many-to-many database-migration laravel-filament
1个回答
0
投票
你找到解决办法了吗?我现在正面临这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.