php - Laravel 尝试将数据传递给 View 时 undefined variable

标签 php mysql laravel

我正在尝试将数据从 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/

相关文章:

javascript - 回显日期的引用错误

php - 尝试从Composer安装laravel时缺少PHP扩展zip

php - 左连接两张表,得到第二张表的记录数

php - magento资源中的version和data_version有什么区别?

MySQL 查找每个区域每个人的最新状态

mysql - 需要用两个不同的 where 子句返回两组数据

php - 如何使用 laravel Eloquent 地从数组数据更新 sql 中的多行

php - laravel 4 ORM 查询运算符

php - 亲子关系

php - 来自数据库的 Slug 可通过 lang CodeIgniter 在所有页面上使用