首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >雄辩关系显示为空

雄辩关系显示为空
EN

Stack Overflow用户
提问于 2020-07-30 00:37:43
回答 1查看 23关注 0票数 0

我有这样的用户和项目迁移:

代码语言:javascript
复制
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();
        });

代码语言:javascript
复制
Schema::create('projects', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('eplan_name')->nullable();
            $table->bigInteger('society_id');
            $table->timestamps();

            //$table->foreign('user_id')->references('id')->on('users');
        });

        Schema::table('projects', function (Blueprint $table) {
            $table->foreign('society_id')->references('id')->on('societies');
        });

表Users在之后被修改为添加外国人:

代码语言:javascript
复制
    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');
    });

在用户模型中,我有这样的设置:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-30 00:41:35

为什么使用'users_last_used_project_id_foreign'?

只需按原样使用列名...

代码语言:javascript
复制
public function ActualProject(){
    return $this->belongsTo('App\Models\Project', 'last_used_project_id');
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63158412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档