pluck('match_id')->toArray(); $description = ' (with '.StatistikoDetail::where('tm_player_id', (int) $tm_player_id)->value('name').')'; } /** * STATTISTIC DATA */ $res = StatistikoEvent::where('league_id', $league_id) ->where(function ($query) use ($team_id, $team_position) { switch ($team_position) { case 'home': return $query->where('home_id', '=', $team_id); case 'away': return $query->where('away_id', '=', $team_id); default: return $query->where('home_id', '=', $team_id) ->orWhere('away_id', '=', $team_id); } })->when($matches_played, function ($query) use ($matches_played) { return $query->whereIn('match_id', $matches_played); })->when($start, function ($query) use ($start) { return $query->where('starttime', '>=', $start); })->when($end, function ($query) use ($end) { return $query->where('starttime', '<=', $end); }) ->orderBy('starttime', 'ASC') ->get(); // dd($res); if ($res == null) { return []; } $total = count($res); // Log::info($res); // Log::info($total); $datasets = []; $labels = []; $labels_since = []; foreach ($res as $value) { $labels[] = $value['starttime']->format('d.M.y'); if ($team_position == 'home') { switch ($statistic_type) { case 'gls': $val = (int) $value['gls_h']; break; case 'crn': $val = (int) $value['crn_h']; break; case 'fls': $val = (int) $value['fls_h']; break; case 'ofs': $val = (int) $value['ofs_h']; break; case 'crd': $val = (int) $value['crd_h']; break; case 'snt': $val = (int) $value['snt_h']; break; case 'tsh': $val = (int) $value['tsh_h']; break; } } elseif ($team_position == 'away') { switch ($statistic_type) { case 'gls': $val = (int) $value['gls_a']; break; case 'crn': $val = (int) $value['crn_a']; break; case 'fls': $val = (int) $value['fls_a']; break; case 'ofs': $val = (int) $value['ofs_a']; break; case 'crd': $val = (int) $value['crd_a']; break; case 'snt': $val = (int) $value['snt_a']; break; case 'tsh': $val = (int) $value['tsh_a']; break; } } else { switch ($statistic_type) { case 'gls': if ($team_id == $value['home_id']) { $val = (int) $value['gls_a']; } else { $val = (int) $value['gls_h']; } break; case 'crn': if ($team_id == $value['home_id']) { $val = (int) $value['crn_a']; } else { $val = (int) $value['crn_h']; } break; case 'fls': if ($team_id == $value['home_id']) { $val = (int) $value['fls_a']; } else { $val = (int) $value['fls_h']; } break; case 'ofs': if ($team_id == $value['home_id']) { $val = (int) $value['ofs_a']; } else { $val = (int) $value['ofs_h']; } break; case 'crd': if ($team_id == $value['home_id']) { $val = (int) $value['crd_a']; } else { $val = (int) $value['crd_h']; } break; case 'snt': if ($team_id == $value['home_id']) { $val = (int) $value['snt_a']; } else { $val = (int) $value['snt_h']; } break; case 'tsh': if ($team_id == $value['home_id']) { $val = (int) $value['tsh_a']; } else { $val = (int) $value['tsh_h']; } break; } } if (isset($val)) { $datasets[] = $val; } } $data = [ 'datasets' => [ [ 'label' => HelperStatisticType::get($filter), 'data' => $datasets, 'fill' => true, 'tension' => 0.5, 'borderColor' => '#36A2EB', ], ], 'labels' => $labels, 'description' => $description ?? '', ]; self::$last_query = $data; return $data; } }