正在创建 Laravel Filament 应用程序。我有 Services 和 Offices 表。我尝试使用 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),
我哪里做得不对?