Code: Select all
public function h2h($game_id)
{
$game = Game::find($game_id);
$team1 = $game->team1;
$team2 = $game->team2;
$games = Game::where('team1', $team1)
->where('team2', $team2)
->orWhere('team1', $team2)
->where('team2', $team1)->get();
$h2h = [];
foreach ($games as $game) {
$team1Goals = count(json_decode($game->stat->team1Goals));
$team2Goals = count(json_decode($game->stat->team2Goals));
$h2h[] = [
'date' => verta($game->date)->format('l d M'),
'team1' => [
'name' => $game->home->name,
'logo' => $game->home->logo,
'goals' => $team1Goals
],
'team2' => [
'name' => $game->away->name,
'logo' => $game->away->logo,
'goals' => $team2Goals
],
];
}
dd($h2h);
return $h2h;
}
Code: Select all
count(json_decode($game->stat->team1Goals));
Versuch, die Eigenschaft „team1Goals“ auf null zu lesen
Wenn dieser Code einer Variablen zugewiesen wird, sagt er, dass er null ist, aber wenn Sie ihn drucken, wird der korrekte Wert gedruckt.