Laravel 雄辩的关系显示为空

Laravel 雄辩的关系显示为空,laravel,eloquent,foreign-keys,Laravel,Eloquent,Foreign Keys,我为以下用户和项目进行了迁移: Schema::create('users', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->n

我为以下用户和项目进行了迁移:

Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->bigInteger('last_used_society_id');
            $table->bigInteger('last_used_project_id');
            $table->rememberToken();
            $table->timestamps();
        });

表用户在添加外来项后被更改:

    Schema::table('users', function (Blueprint $table) {
        $table->foreign('last_used_society_id')->references('id')->on('societies');
        $table->foreign('last_used_project_id')->references('id')->on('projects');
    });
在用户模型中,我有:

public function ActualProject(){
    return $this->belongsTo('App\Models\Project', 'users_last_used_project_id_foreign');
}

public function ActualSociety(){
    return $this->belongsTo('App\Models\Society', 'users_last_used_society_id_foreign');
}

但是当我试图调用
$user->ActualProject
时,它返回
null
为什么使用“users\u last\u used\u project\u id\u foreign”

只需按原样使用列的名称

public function ActualProject(){
    return $this->belongsTo('App\Models\Project', 'last_used_project_id');
}

为什么使用“用户\上次使用\项目\标识\外来”

只需按原样使用列的名称

public function ActualProject(){
    return $this->belongsTo('App\Models\Project', 'last_used_project_id');
}

美好的谢谢你不知道我可以用列名。。。我在网上发现的是使用外国语言key@Petr,如果您的外国id是
project\u id
,那么您不需要在您的关系中定义它。拉威尔会把它拍下来的。您需要修改,所以您需要告诉laravel您的主键名.nice。谢谢你不知道我可以用列名。。。我在网上发现的是使用外国语言key@Petr,如果您的外国id是
project\u id
,那么您不需要在您的关系中定义它。拉威尔会把它拍下来的。您需要修改,因此需要告诉laravel您的主键名称。