Use modelKeys() on the Eloquent Builder in Laravel 13.24

Punyapal Shah
Laravel 13.24 adds modelKeys() directly to the Eloquent query builder, replacing hardcoded pluck('id') calls with a method that uses the model primary key.

Instead of hardcoding column strings like pluck('id'), calling modelKeys() on the query builder automatically respects custom primary key configurations defined on the target model.

use App\Models\User;

// Replaces User::where('active', true)->pluck('id')
$ids = User::where('active', true)->modelKeys();
  • Replaces pluck('id') with a model-aware alternative
  • Automatically respects custom $primaryKey definitions
  • Previously only available on Eloquent Collections, now works on the builder
Tags: #Laravel #Eloquent #Database
Share on X

// Found an issue or want to contribute a tip? github.com/MrPunyapal/tips