Php Laravel 4符合何处条件

Php Laravel 4符合何处条件,php,laravel-4,many-to-many,Php,Laravel 4,Many To Many,我有以下数据库结构: 卡片表与类型有多对多关系,类型可以有以下三种元类型之一: 超型 亚型 类型 在我的卡模型中,我希望有以下方法: types()->“…其中types.metatype='type'” supertypes()->“…其中types.metatype='supertype'” subtypes()->“…其中types.metatype='subtype'” 是否可以在types表(而不是pivot)上添加where来实现这一点 在此之前,我有3个不同的表: 卡片

我有以下数据库结构:

卡片表与类型有多对多关系,类型可以有以下三种元类型之一:

  • 超型
  • 亚型
  • 类型
在我的卡模型中,我希望有以下方法:

  • types()->“…其中types.metatype='type'”
  • supertypes()->“…其中types.metatype='supertype'”
  • subtypes()->“…其中types.metatype='subtype'”
是否可以在types表(而不是pivot)上添加where来实现这一点

在此之前,我有3个不同的表:

  • 卡片类型
  • 超类型
  • 卡类
但这似乎不是一个好主意,因为类型表中已经存在元类型数据,所以我不希望通过复制关系表来“重复”此信息。

这可能会起作用:

public function supertype() {
    return $this->belongsToMany('Card')->where('metatype','=','supertype');
}

public function subtype() {
    return $this->belongsToMany('Card')->where('metatype','=','subtype');
}

public function type() {
    return $this->belongsToMany('Card')->where('metatype','=','type');
}

谢谢,我用另一种方法解决了这个问题,但你的答案确实有效:)你能告诉我们怎么做吗?谢谢:)