模型关系

时间:2019-09-09 12:07:53

标签: laravel eloquent

问题是我将关系添加到模型中,PHPstorm表示功能室是一个“未使用的元素”,并且该关系确实起作用。

我已经浏览过laravel的文档,并在google上搜索了解决方案

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Type extends Model
{
    public function rooms()
    {
        return $this->hasMany('App\Room');
    }
}

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Room extends Model
{
    public function type(){
        return $this->belongsTo('App\room');
    }
}

该关系应在我看来提供房间号,目前为空

1 个答案:

答案 0 :(得分:3)

似乎您在类型方法中提到了错误的关系。

public function type(){
    return $this->belongsTo('App\Type');
}