2 years ago

mapWithKeys only return one item

Posted 2 years ago by ramjamx

I want to change the date format in the return array of this query, but I'm getting only the last user instead all users, as if I return $users variable.

$users  = DB::table('users')->select('id',

  $users_formated = $users->mapWithKeys(function($user){
      $lastupdate =  strtotime($user->last_update);
      return ['_id' => $user->id,
              'username' => $user->username,
              'last_update' => (string) $lastupdate,

  return $users_formated->all();

I tried with a foreach but same result :(

Any help?

Please sign in or create an account to participate in this conversation.