使用laravel。我在mysql数据库中有下面的表。
infos表接受1个中介(表中介)和1个存储(表存储)。如何从infos表中获取所有数据?但仅当透视表(中间存储)处于活动状态时=1?
infos
- id
- name
- intermediary_id
- store_id
intermediaries
- id
- name
intermediary_store
- intermediary_id
- store_id
- active
stores
- id
- name
模型:
class Info extends Model
{
public function intermediary()
{
return $this->belongsTo('App\Intermediary');
}
public function store()
{
return $this->belongsTo('App\Store');
}
}
class Intermediary extends Model
{
public function stores()
{
return $this->belongsToMany('App\Store')->withPivot('active');
}
}
class Store extends Model
{
public function intermediaries()
{
return $this->belongsToMany('App\Intermediary')->withPivot('active');
}
}
暂无答案!
目前还没有任何答案,快来回答吧!