Use withoutRelation() or unsetRelation() to remove eager loaded relationships on specific Eloquent queries or model instances.
Models with $with properties eager load relations globally on every query. Use withoutRelation() on query builders to bypass global eager loads when relations are unneeded.
use App\Models\Post;
// Model defines protected $with = ['author', 'comments'];
// Query: Exclude 'comments' relation for this specific query
$posts = Post::withoutRelation('comments')->get();
// Instance: Unset loaded relation on an existing model object
$post->unsetRelation('comments');
- Bypasses default $with eager loading definitions per-query
- unsetRelation() clears in-memory relation data on model instances
- Reduces unnecessary database subqueries for specific lightweight queries
Related Tips
View all tips →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.
Update Pivot Table Attributes Directly with updateExistingPivot()
Use updateExistingPivot() on belongsToMany relationships to update intermediate table columns without detaching or re-attaching models.