tgif
3 years ago

Retriving the user(s) models

Posted 3 years ago by tgif

Hi, I need the actual user models rather than the collection of data. How do I retrieve an array of User models I've been using this:

$users = DB::table('users')
                ->whereIn('id', $userIds)
                ->get();

RETURNS:

array:4 [▼
  0 => {#204 ▼
    +"id": 1
    +"recipient": 1
    +"account_type": "Individual"
    +"name": "Paul"
    +"last_name": "McCartney"
    +"email": "[email protected]"
    +"password": "$2y$10$5AHYqAfSLA6huE0k4b5xg.S15DC1B7r//LO9DC8cCwKXzSn9.YBVG"
    +"address": "sdghfdsgfds"
    +"city": "gfdsgfds"
    +"state": "gfdsgfds"
    +"postal_code": "gfdsgfds"
    +"country": "gfdsgfds"
    +"phone_number": "gfdsgfds"
    +"industry": "gfdsgfds"
    +"category": "gfdgfds"
    +"avatar": ""
    +"field1": ""
    +"field2": ""
    +"field3": ""
    +"field4": ""
    +"field5": ""
    +"field6": ""
    +"field7": ""
    +"field8": ""
    +"field9": ""
    +"remember_token": "mqYiKbXhudPiROS3lJWjDfaxKW4Afk80iLSvWoLTYsCMwNQov5q95dGd"
    +"created_at": "2016-06-04 03:47:07"
    +"updated_at": "2016-06-04 03:47:48"
  }
  1 => {#200 ▶}
  2 => {#206 ▶}
  3 => {#218 ▶}
]

But what I need is an array of User models

User {#203 ▼
  #fillable: array:23 [▼
    0 => "name"
    1 => "last_name"
    2 => "email"
    3 => "recipient"
    4 => "password"
    5 => "address"
    6 => "city"
    7 => "state"
    8 => "postal_code"
    9 => "country"
    10 => "phone_number"
    11 => "industry"
    12 => "category"
    13 => "field1"
    14 => "field2"
    15 => "field3"
    16 => "field4"
    17 => "field5"
    18 => "field6"
    19 => "field7"
    20 => "field8"
    21 => "field9"
    22 => "account_type"
  ]
  #hidden: array:2 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: array:28 [▶]
  #original: array:28 [▶]
  #relations: []
  #visible: []
  #appends: []
  #guarded: array:1 [▶]
  #dates: []
  #dateFormat: null
  #casts: []
  #touches: []
  #observables: []
  #with: []
  #morphClass: null
  +exists: true
  +wasRecentlyCreated: false
}
}

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