Skip to main content
Quick Tip

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_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"
}
]
*/

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

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.