0

I try to manipulate a Collection based on a request include in a foreach .. As an ouput i receive a Collection with an array of object ...

What i need is a Collection of array witch contain my attributes ... This is what i have with a dd($users) :

Collection {#551 ▼
  #items: array:16 [▼
    0 => User {#610 ▼
      #table: "users"
      #fillable: array:13 [▶]
      #guarded: array:1 [▶]
      #hidden: array:2 [▶]
      #timestamp: true
      #softDelete: true
      #attributes: array:15 [▼
        "id" => 1
        "ua_id" => 351
        "grade_id" => 584
        "metier_id" => 18
        "nom" => "xxxx"
        "prenom" => "xxxx"
        "matricule" => "xxxx"
        "email" => null
        "datenaissance" => "xxxx"
        "password" => "xxxxx"
         ...

And this is what i want :

Collection {#2114 ▼
  #items: array:16 [▼
    1 => array:15 [▼
        "id" => 1
        "ua_id" => 351
        "grade_id" => 584
        "metier_id" => 18
        "nom" => "xxxx"
        "prenom" => "xxxx"
        "matricule" => "xxxx"
        "email" => null
        "datenaissance" => "xxxx"
        "password" => "xxxxx"
         ...
davidvera
  • 1,292
  • 2
  • 24
  • 55

1 Answers1

2

Try to use

$newCollection = collect($oldCollection->toArray());

this will transform your old collection to array and this array to collection.

Lucas Hart
  • 66
  • 4