Model all(): Specify Columns

When calling Eloquent's Model::all(), you can specify which columns to return.

$users = User::all();
 
/* RESULT:
all: array:1 [▶
0 => App\Models\User {#3200 ▼
id: 1
name: "Prof. Koby Koss PhD"
email: "geovanni.schulist@example.org"
email_verified_at: "2024-03-23 08:09:45"
#password: "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi"
#remember_token: "QYQxckH6ki"
created_at: "2024-03-23 08:09:45"
updated_at: "2024-03-23 08:09:45"
}
]
*/
 
$users = User::all(["id", "name", "email"]);
 
/* RESULT:
all: array:1 [▶
0 => App\Models\User {#3216 ▼
id: 1
name: "Prof. Koby Koss PhD"
email: "geovanni.schulist@example.org"
}
]
*/

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1057 lessons, total 42 h 44 min)
  • 79 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials