I have User model when I tried to return all users like this query
$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 ...
}
That’s work fine, but when I return this from ubuntu server – the response will be like this
"created_at": [],
Also, if I tried to return Carbon::now()
the server return null array like this []
and in local working fine.
2
Answers
I solved the problem by changing the php version from php7.4 into php7.2
Try this:
Laravel mapWithKeys