Skip to content

[13.x] Add modelKeys() to Eloquent query builder - #60924

Merged
taylorotwell merged 4 commits into
laravel:13.xfrom
ziadoz:query-builder-model-keys
Jul 29, 2026
Merged

[13.x] Add modelKeys() to Eloquent query builder#60924
taylorotwell merged 4 commits into
laravel:13.xfrom
ziadoz:query-builder-model-keys

Conversation

@ziadoz

@ziadoz ziadoz commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This PR adds a modelKeys() method to the Eloquent query builder, similar to what collections have:

Posts::query()->where(...)->modelKeys(); // [1, 2, 3]

I prefer to avoid hardcoding primary key field names in code if possible (I see pluck('id') a lot), and it's an inconsistency when compared to being able to get the keys from a model ($model->getKey()) or collection ($models->modelKeys()). It's would also be quite handy for testing too tbh.

@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@ziadoz
ziadoz marked this pull request as ready for review July 29, 2026 12:16
@taylorotwell
taylorotwell merged commit 927e73d into laravel:13.x Jul 29, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants