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