问题描述
我正在尝试在 laravel 中使用数据表,但得到以下响应:
{
"message": "foreach() argument must be of type array|object,null given","exception": "ErrorException",
我已经在我的控制器中尝试过这段代码:
$dataLists= DB::table("table_name")
->select('column_1','column_2')
->get();
return Datatables::of($dataLists)
->make(true);
如果我打印 $datalists 它会以下面的格式显示数据
Illuminate\Support\Collection Object
(
[items:protected] => Array
(
[0] => stdClass Object
(
[column_1] => 386932
[column_2] => data name 1
)
[1] => stdClass Object
(
[column_1] => 8764358
[column_2] => data name 2
)
)
)
我的php版本是:8.0.0 Laravel 版本为:8.20.1
有人可以帮我找出我错在哪里吗?
解决方法
只需清除laravel的配置缓存php artisan config:cache