Laravel 10 + Filament v3 错误调用成员函数 getForeignKeyName() on null

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

我不知道为什么它不起作用,也不知道在哪里或诚实地寻找什么。我有主桌

access_permits

结构

id
permit_id
type
user_relationship_id
vehicle_relationship_id
request_date
expire_date
status
created_at
updated_at

这是另一个表

access_permit_vehicles
,它具有多对多关系

结构:

id
access_permit_id
vehicle_id
created_at
updated_at

车辆型号:

public function accessPermits(): BelongsToMany
    {
        return $this->belongsToMany(AccessPermit::class, 'access_permit_vehicles', 'vehicle_id', 'access_permit_id');
    }

访问许可证型号:

public function vehiclesRelationship(): BelongsTo
    {
        return $this->belongsTo(Vehicle::class);
    }

    public function vehicles(): BelongsToMany
    {
        return $this->belongsToMany(Vehicle::class, 'access_permit_vehicles', 'access_permit_id', 'vehicle_id');
    }

这是

access_permit_vehicles
的迁移:

Schema::create('access_permit_vehicles', function (Blueprint $table) {
            $table->id();
            $table->foreignId('access_permit_id')->constrained('access_permits')->onDelete('cascade');
            $table->foreignId('vehicle_id')->constrained('vehicles')->onDelete('cascade');

            $table->timestamps();
        });

这是为了

access_permits

Schema::create('access_permits', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('permit_id')->unique();  // Adjusted to unsignedInteger for proper ID type

            // Other columns as defined
            $table->string('type')->index();
            $table->unsignedBigInteger('user_relationship_id');
            $table->unsignedBigInteger('vehicle_relationship_id');
            $table->dateTime('request_date');
            $table->dateTime('expire_date');
            $table->string('status')->default(\App\Enum\PermitStatus::Active);

            $table->timestamps();

            // Foreign key constraints
            $table->foreign('user_relationship_id')->references('id')->on('users')->onDelete('cascade');
            // Ensure the foreign key for vehicle_relationship_id if needed
            $table->foreign('vehicle_relationship_id')->references('id')->on('vehicles')->onDelete('cascade');
        });
laravel foreign-keys laravel-filament filamentphp
1个回答
0
投票

遗憾的是……所有这些挣扎都是:

该方法名为

vehicleRelationship()
,但我称其为
vehiclesRelationship()

S 是个冒名顶替者。

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