中间表数据模型的定义RoleUser写错了么
相关信息:
- 类型:文档文章
- 文章: 模型关联
- 文档: 《Laravel 6 中文文档(6.x)》
此投稿已在 6年前 合并。
内容修改:
| Old | New | Differences |
|---|---|---|
| 337 | 337 | <a name="defining-custom-intermediate-table-models"></a> |
| 338 | 338 | ### 定义中间表模型 |
| 339 | 339 | |
| 340 | 如果你想定义一个自定义模型来表示关联关系中的中间表,可以在定义关联时调用 `using` 方法。自定义多对多中间表模型都必须扩展自 `Illuminate\Database\Eloquent\Relations\Pivot` 类,自定义多对多(多态)中间表模型必须继承 `Illuminate\Database\Eloquent\Relations\MorphPivot` 类。例如,我们在写 `Role` 模型的关联时,使用自定义中间表模型 ` | |
| 340 | 如果你想定义一个自定义模型来表示关联关系中的中间表,可以在定义关联时调用 `using` 方法。自定义多对多中间表模型都必须扩展自 `Illuminate\Database\Eloquent\Relations\Pivot` 类,自定义多对多(多态)中间表模型必须继承 `Illuminate\Database\Eloquent\Relations\MorphPivot` 类。例如,我们在写 `Role` 模型的关联时,使用自定义中间表模型 `RoleUser`: | |
| 341 | 341 | |
| 342 | 342 | <?php |
| 343 | 343 | … | … |
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 当定义 ` | |
| 359 | 当定义 `RoleUser` 模型时,我们要扩展 `Pivot` 类: | |
| 360 | 360 | |
| 361 | 361 | <?php |
| 362 | 362 |
关于 LearnKu