0
我有4个桌子,想把它们绑在一起,但我迷路了。Laravel 1 foriegn键,2桌雄辩ORM
User
'id'
'name' // etc...
Product
'id'
'name' // etc...
AnonCart
'id'
'unique_id' //tied to session id
'product_id' // tied to 'id' of Product
'quantity' //
UserCart
'id'
'user_id' //tied to 'id' of User
'product_id' // tied to 'id' of Product
'quantity' //
我试图建立雄辩这些关系对我的Laravel项目
我有以下
user.php的
public function userCarts()
{
$this->hasMany('\Namespace\UserCart');
}
UserCart.php
public function user()
{
$this->belongsTo('\Namespace\User');
}
public function product()
{
$this->belongsTo('\Namespace\Product');
}
AnonUser.php
// doesn't have a user tied to it...
public function product()
{
$this->belongsTo('\Namespace\Product');
}
最后,我不;知道这里做什么。我不知道如何界定产品的关系,以车
Product.php
public function carts()
{
$this->hasMany('\Namespace\UserCart'); // AnonCart??
}
我该如何解决具有链接到2级不同的表的产物,但具有相同关键字的问题在两张桌子上?
是它具有2种方法(anonCarts()和userCarts()?)简单
是的,只是有2种方法。也许是'userCarts'方法和'anonCarts'方法。 – slapyo 2014-12-04 17:06:50