【发布时间】:2019-05-30 03:41:06
【问题描述】:
我正在尝试运行一个查询来计算用户参与活动的次数,但我收到了以下错误:
试图获取非对象的属性“游戏”
还有下划线:
<td><?php echo e($player->game); ?></td>
我已经写好了查询
控制器
$players = DB::table("played_game")
->select("played_game.user_id","played_game.game","users.username", DB::raw("COUNT(played_game.game) as no_game"))
->join("users","users.id","=","played_game.user_id")
->groupBy("played_game.game","users.username","played_game.user_id")
->orderByRaw('COUNT(played_game.game) DESC')
->paginate(15);
查看
@foreach ($players as $key => $player_list)
<tr>
<th colspan="3"
style="background-color: #F7F7F7">{{ $player_list->username }}</th>
</tr>
@foreach ($player_list as $player)
<tr>
<td>{{ $player->game }}</td>
<td>{{ $player->no_game }}</td>
</tr>
@endforeach
@endforeach
我想在 td 中显示涉及 colspan 的玩家(用户名)和其他详细信息。
【问题讨论】:
-
因为
$players是空的? -
没有。 $players 不为空
-
你能转储
$players值吗? -
$player不是你想象的那样。它可能是字符串或其他东西,但它不是对象,因此您无法访问属性。也许在那个循环中做一个dd($player)。 -
$player_list是一个数组吗?
标签: laravel