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
Laravel Coding with AI Agents: Cursor, Claude Code, Codex
5 lessons
1 h 01 min
Laravel 12 For Beginners: Your First Project
15 lessons
1 h 32 min
NativePHP: Build Mobile App with Laravel
11 lessons
2 h 2 min read