【发布时间】:2015-04-16 22:09:01
【问题描述】:
我是 Laravel 的新手,我正在尝试创建模型之间的关系。我的桌子是:
patch
id
title
area
id
location
area_patch
id
patch_id
area_id
user_area_patch
id
area_patch_id
plant_id
plant_date
用户模型,“补丁”函数应该像这样执行:
SELECT
p.id, p.title, up.plant_id, up.plant_date
FROM
rsst_farming_patch p
JOIN rsst_farming_area_patch pp,
rsst_farming_user_patch up ON pp.id = up.area_patch_id AND p.id = pp.patch_id WHERE up.user_id = 1
我的模型:
class User extends Model {
public function patchs() {
//return user patchs
}
}
class Patch extends Model {
public function area() {
//return area that this patch belongs to
}
}
class Area extends Model {
public function patchs() {
//return available patchs
}
}
有人可以举个例子吗?我想研究它。我在搞乱用户模型,belongsToMany 和 hasManyThrough,但没有运气。
【问题讨论】:
-
Laravel 5 现在在关系声明中使用命名空间,你忘记了吗?而且,您能否更明确地解释一下(?)您要做什么以及如何做!