// Изменить: получение счетчиков
Код: Выделить всё
$begin = new \DateTime($from);
$end = new \DateTime($to);
$end = $end->modify('+1 day');
// find points and meters by group
$grouping = App\Grouping::with('points.meters')->find($group_id);
$meter_plus = [];
$meter_minus = [];
// each group has one-to-many points, each point has one-to-many meters
foreach($grouping->points as $point) {
foreach($point->meters as $meter) {
if($meter->Relation == '+') {
array_push($meter_plus, $meter);
} else {
array_push($meter_minus, $meter);
}
}
}
Код: Выделить всё
public function meters()
{
return $this->belongsToMany('App\EnergyMeter', 'meteringpoint_energymeter_relation', 'point_id', 'meter_id')
->whereHas('users', function ($q) {
$q->where('UserID', Auth::id());
})
->where('Deleted', 0)
->select('*', 'meteringpoint_energymeter_relation.Relation')
->orderBy('EMNumber');
}
Код: Выделить всё
$plus = Data::selectRaw('sum(values) as data')
->where('PointOfTime', '>', $begin->format('U'))
->where('PointOfTime', '', $begin->format('U'))
->where('PointOfTime', '
Подробнее здесь: [url]https://stackoverflow.com/questions/28696875/eloquent-simplify-combine-query[/url]
Мобильная версия