winter-ice 5年前

修改理由:

方法名写错

相关信息:


此投稿已在 5年前 合并。

内容修改:

红色背景 为原始内容

绿色背景 为新增或者修改的内容

OldNewDifferences
1  
21# Eloquent: 关联
32
43- [简介](#introduction)
 
121120       return $this->belongsTo('App\User', 'foreign_key', 'other_key');
122121   }
123122
124 
 123
125124<a name="one-to-many"></a>
126125### 一对多
127126
 
212211       return $this->belongsTo('App\Post', 'foreign_key', 'other_key');
213212   }
214213
215 
 214
216215<a name="many-to-many"></a>
217216### 多对多
218217
 
318317       echo $podcast->subscription->created_at;
319318   }
320319
321 
 320
322321
323322#### 通过中间表列过滤关系
324323
 
522521
523522你可以在 `AppServiceProvider` 中的 `boot` 函数中使用 `Relation::morphMap` 方法注册「多态映射表」,或者使用一个独立的服务提供者注册。
524523
525 
 524
526525<a name="many-to-many-polymorphic-relations"></a>
527526### 多对多的多态关联
528527
 
768767echo $posts[0]->comments_count;
769768
770769echo $posts[0]->pending_comments_count;
771 ```
 770```
772771<a name="eager-loading"></a>
773772## 懒加载
774773
 
889888}]);
890889```
891890
892 当关联关系没有被加载时,你可以使用使用 `loadMission` 方法:
 891当关联关系没有被加载时,你可以使用使用 `loadMissing` 方法:
893892
894893```
895894public function format(Book $book)
 
903902}
904903```
905904
906 
 905
907906
908907<a name="inserting-and-updating-related-models"></a>
909908## 插入 & 更新关联模型
 
10081007       });
10091008   }
10101009
1011 
 1010
10121011
10131012<a name="updating-many-to-many-relationships"></a>
10141013### 多对多关联