Laravel 在控制台中显示来自 table 的数组,即使是空值

Laravel show array in console from table even with null values

这是我的table:hms_bbr_category_2。测试而已table,无视乱码

我需要让 console.log 正常工作,以防万一我添加新行时值会出现任何空数据

这是我的 Laravel 控制器:(我的型号是 HmsBbrCategory 并连接到 table)

public function fetchcategory() {
    $all_categories = HmsBbrCategory::all();
    return response()->json([
        'all_categories'->$all_categories,
    ]);
}

Ajax

function fetchcategory() {
    $.ajax({
        type: "GET",
        url: "/clinical/bbr-category-configuration-data",
        dataType: "json",
        success: function (response){
            console.log(response.all_categories);
        }
    });
}

当我尝试显示 table:

时,我的控制台发出此错误

message: "Trying to get property (list of the table arrays) of non-object"

显示错误是因为我的某些列为空吗?即使是空值,我该怎么做才能输出数据?

返回响应时出错'all_categories'->$all_categories,

public function fetchcategory(){
    $all_categories = HmsBbrCategory::all();
    return response()->json([
        'all_categories'=>$all_categories,
    ]);
}

您在 fetchcategory() 方法中返回 JSON 响应时出错:

代替这行代码:

return response()->json([
    'all_categories'->$all_categories,
]);

使用这行代码:

return Response::json(array('all_categories' => $all_categories));