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