0
对于我工作的一个Laravel应用,我愿做这样的事情与我的口才型号:Laravel 4雄辩许多一对多条件参数
$product = Product::with('terms')->find(1);
$brand = $product->terms('brand');
$color = $product->terms('color');
的来讲是一个多对多关系。这里的术语是分类术语。所以一个产品的条款可以是:耐克,红色,男孩等 如果我做$product->terms
我得到的所有条款,当我做$product->terms('brand')
我得到'耐克'例如。
现在我的产品型号是这样的:
class Product extends Eloquent {
protected $guarded = array();
public static $rules = array();
public function terms($taxonomy)
{
return $this->belongsToMany('Term', 'productterms');
}
}
它甚至有可能做什么,我想达到什么目的?