Laravel Carbon::now() 方法在 ubuntu 服务器上返回 null

Laravel Carbon::now() method returning null on ubuntu server

当我尝试 return 所有用户都喜欢这个查询时,我有用户模型

 $users = User::all();

    $userCollections = (object)collect([]);
    foreach ($users as $user)
    {
        $userCollections['name'] = $user->name,
        $userCollections['date'] = $user->created_at; // here working fine in local but in server
//returning null array like this [] and its in database like this -> 2020-06-30 13:11:01
        ...
        ..
        etc ...
    }

这很好用,但是当我从 ubuntu 服务器 return 这时 - 响应将是这样的

"created_at": [],

此外,如果我尝试 return Carbon::now() 服务器 return 像这样的空数组 [] 并且在本地工作正常。

试试这个:

$userCollections = User::all()->mapWithKeys(function ($user) {
    return [['name' => $user->name, 'date' => $user->created_at]];
})

Laravel mapWithKeys

我通过将 php 版本从 php7.4 更改为 php7.2

解决了这个问题