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
Related Tips
View all tips →Refresh and Pessimistically Lock Models with refreshForUpdate() in Laravel 13.27
Laravel 13.27 adds refreshForUpdate(), reloading an existing model instance in-place with fresh database attributes while acquiring an exclusive FOR UPDATE row lock.
Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models.