Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/146.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 如何修复类Illumb\Database\Eloquent\Collection的错误对象无法转换为int_Laravel - Fatal编程技术网

Laravel 如何修复类Illumb\Database\Eloquent\Collection的错误对象无法转换为int

Laravel 如何修复类Illumb\Database\Eloquent\Collection的错误对象无法转换为int,laravel,Laravel,我的页面应该显示来自不同表的总和。当我尝试使用代码进行求和时: $games = Game::where('winner_id', $user->id)->get(); $games_low = GameLow::where('winner_id', $user->id)->get(); $wins = $games + $games_low->count(); $wins = $wins;

我的页面应该显示来自不同表的总和。当我尝试使用代码进行求和时:

        $games = Game::where('winner_id', $user->id)->get();
        $games_low = GameLow::where('winner_id', $user->id)->get();
        $wins = $games + $games_low->count();
        $wins = $wins;
        $totalBank = $games->sum('price');
我收到错误
无法将类Illumb\Database\Eloquent\Collection的对象转换为int
。如何解决此问题?

问题-收集 使用
+
对象(
$games
)和数字(
$games\u low->count()
)时出错

$games=Game::where('winner_id',$user->id)->get();//收集
$games\u low=GameLow::where('winner\u id',$user->id)->get();//收集
$games\u low->count()//int
解决方案 使用
count
进行
Game
GameLow

$games=Game::where('winner_id',$user->id)->count();
$games\u low=GameLow::where('winner\u id',$user->id)->count();
$wins=$games+$games\u low;
dd($wins);

更新 如何正确显示变量之和?以前,当我有一个变量时,我使用
$totalBank=$games->sum('price')我现在需要如何显示sum
$games
$games\u low
,我不知道

$games=Game::where('winner\u id',$user->id);
$games\u low=GameLow::where('winner\u id',$user->id);
$wins=$games->count()+$games_low->count();
$totalBank=$games->sum('price');

什么是
$gamesPlayed
?这是数据库中显示的游戏计数,我没有在blade上使用
$winrate
$gamesPlayed
变量,我编辑我的问题。是的,它有效!!最后一个问题:如何正确显示变量之和?以前,当我有一个变量时,我使用
$totalBank=$games->sum('price')我现在需要如何显示总和
$games
$games\u low
,我不知道检查我的答案:)