Laravel从数据透视表中检索状态
我有表、工作站和设备,第三个数据透视表Station\u Equipment,除了各自的表ID外,还有其他字段“status”,状态可以是active(活动)或inactive(非活动),我只想获取活动元素,但我的查询继续检索具有这两种状态的设备 查询:Laravel从数据透视表中检索状态,laravel,laravel-5,Laravel,Laravel 5,我有表、工作站和设备,第三个数据透视表Station\u Equipment,除了各自的表ID外,还有其他字段“status”,状态可以是active(活动)或inactive(非活动),我只想获取活动元素,但我的查询继续检索具有这两种状态的设备 查询: $eqestacion = Station::where('station.id', $id) ->whereHas('equipments', function($query) {
$eqestacion = Station::where('station.id', $id)
->whereHas('equipments', function($query) {
$query->where('equipment_station.status','=','active');
})->with('equipments')
->get();
车站型号:
public function equipments(){
return $this->belongsToMany('App\Equipment')->withPivot('status')->withTimestamps();
}
设备型号:
public function stations()
return $this->belongsToMany('App\Station')
->orderBy('pivot_created_at','desc')->withPivot('status')->withTimestamps();
}
提前感谢这将为您提供一个id为$id的
电台
:
$station = Station::findOrFail($id);
这将为您提供与$站相关的所有活动设备
$station->equipments()->wherePivot('status', 'active')->get();
我怎么也能得到车站的数据呢?