/
Ahed
/
Football-analyzer
Обзор
Документация
Войти
/
Ahed
/
Football-analyzer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
app/Http/Controllers/FrontController.php
64 строки
2 KB
Ахед Шаабан
first_commit
18 дек 2025, 17:21
18 дек 2025, 17:21
3c7ec38
Код
Авторство
О чём код?
<?php namespace App\Http\Controllers; use App\Models\Fixture; use App\Models\League; use App\Models\Team; use Illuminate\Http\Request; class FrontController extends Controller { public function index(){ // выбор лиги $leagues = League::query()->select('id', 'name')->get(); return view('front', compact('leagues')); } public function teams($leagueId){ // выбор команды //$league = League::query()->where('api_id', '=', $leagueId)->firstOrFail(); $teams = Team::query()->where('league_id','=', $leagueId)->select('id','name')->get(); return response()->json($teams); } public function analytics($teamId, Request $request){ // построение графика и статистики $season = $request->input('season', 2022); $team = Team::query()->where('id', '=', $teamId)->firstOrFail(); $fixtures = Fixture::query() ->where('team_id', '=', $team->id) ->where('season', '=', $season) ->orderBy('date') ->get(); $goalsData = $fixtures->map(function($fixture, $index) { return [ 'match_number' => $index + 1, 'goals_for' => $fixture->goals_for, ]; }); $wins = $fixtures->where('result', 'win')->count(); $losses = $fixtures->where('result', 'loss')->count(); $draws = $fixtures->where('result', 'draw')->count(); $avgGoals = $fixtures->avg('goals_for'); if ($avgGoals === null) { $avgGoals = 0; // ← Установите значение по умолчанию } $maxGoals = $fixtures->max('goals_for'); $winRate = $fixtures->count() ? round($wins / $fixtures->count() * 100, 2) : 0; return response()->json([ 'team' => $team->id, 'goalsData' => $goalsData, 'wins' => $wins, 'losses' => $losses, 'draws' => $draws, 'avgGoals' => $avgGoals, 'maxGoals' => $maxGoals, 'winRate' => $winRate ]); } }