Код: Выделить всё
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;
}
Код: Выделить всё
count(json_decode($game->stat->team1Goals));
Попытка прочитать свойство «team1Goals» со значением null
Этот фрагмент кода, присвоенный переменной, сообщает, что она равна нулю, но когда вы его печатаете, печатается правильное значение.
Подробнее здесь: https://stackoverflow.com/questions/793 ... not-assign