eloquent 父模型的关系和信息

eloquent relationships and information about the parent model

您好,我从 laravel 开始,我想生成一个列表 品牌及其型号。

例如:

福特:野马,远征

GMC:麦金利

这些是我的表格:

makes
    - id
    - name

models
    - id
    - name
    - make_id

我加了

public function models()
{
    return $this->hasMany('App\Make');
} 

到 Make 模型,之后我可以使用

$models = Make::find(1)->models;

即 returns 型号列表(但没有关于品牌的信息) 我还需要获取所有品牌及其型号,而不仅仅是 1

更改这段代码:

public function models()
{
    return $this->hasMany('App\Make');
}

public function models()
{
    return $this->hasMany('App\Model');
}