说我想存储有关客户的各种数据位,所以我有两个型号由枢轴表链接,存储客户的值在枢轴表中的每个数据字段类型:Laravel范围由枢数据值
Customer {
public function datafields()
{
return $this->belongsToMany('Datafield')->withPivot('value');
}
}
和
Datafield {
public function customers()
{
return $this->belongsToMany('Customer')->withPivot('value');
}
所以我的表是客户,customer_datafield,数据域。
如何在客户中设置查询范围以查找特定数据字段值为x的所有客户?
东西沿着
Customer {
public function datafields()
{
return $this->belongsToMany('Datafield')->withPivot('value');
}
public function scopeSearch($query, $searchfor)
{
return $query->datafields()->pivot()
->where('value', $searchfor)
->where('datafield_id', 123);
}
}
行我已经尝试了一些方法,但没有任何运气歌厅一个工作。任何建议非常感谢!
辉煌,一个详细的解答和伟大工程。非常感谢! – Rob 2014-09-27 13:19:03