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: "[email protected]" 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: "[email protected]" } ]*/
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses
[NEW] Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
Laravel 13 Eloquent: Expert Level
41 lessons
1 h 34 min
Laravel AI SDK: 6 Practical Examples
9 lessons
1 h 02 min