我正在尝试将数据从 Controller 传递到 View ,但收到 undefined variable 错误。 usersID 是我的 MySQL 表中的一列。
这是我的 Controller 中的代码
$arrayWithCount = DB :: table("users_has_activities")
-> where("usersID", "=", 19)
-> pluck("usersID");
$countNumber = sizeof($arrayWithCount);
return view('pages.progress', ['countNumber' => $countNumber]);
我也尝试了以下返回语句,但没有成功
return view::make('pages.progress') -> with('countNumber', $countNumber);
我也尝试过反转 puck 和 where 子句,但没有成功,我对反转它们能解决问题没有抱太大希望,但我想我会尝试任何方式。下面是blade文件中的相关代码。
<?php echo $countNumber; ?>
这是我当前遇到的错误
Undefined variable: countNumber
最佳答案
您的代码看起来不错,如果dd()
没有停止 Controller 的执行,则另一个 Controller 正在执行。因此,请仔细检查您的路线和 Controller 。
关于php - Laravel 尝试将数据传递给 View 时 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36132681/