Fix Table attribute incrementing not working for Pivot models#59336
Merged
taylorotwell merged 2 commits intolaravel:13.xfrom Mar 23, 2026
Merged
Fix Table attribute incrementing not working for Pivot models#59336taylorotwell merged 2 commits intolaravel:13.xfrom
taylorotwell merged 2 commits intolaravel:13.xfrom
Conversation
The `#[Table]` attribute includes an argument to specify whether the primary key should be incrementing. However, for Pivot models that default to non-incrementing, the Table attribute's incrementing argument was not being applied because the logic only checked it when `$this->incrementing === true`. This fix removes the outer condition so that the Table attribute can override the default incrementing behavior for all models, including Pivots.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #59335
This PR solves an issue where using the
#[Table]attribute on a Pivot model fails to configure itsincrementingprimary key property correctly. For regular model classes, theincrementingargument acts as a drop-in replacement layout over the classic$incrementing = true;property styling.🚨 The core issue
Pivot models default to non-incrementing primary keys:
Inside Illuminate\Database\Eloquent\Model::__construct, there exists logic that attempts to sync attributes from #Table classes, but includes an isolated safeguard:
Because of this specific outer validation barrier, the static $incrementing = false definition explicitly placed inside the parent Pivot class overrides the attribute statement, locking the model fully from applying the toggle config back to true.
💡 Solution
I've updated the logic by removing the outer check. Eliminating the condition lets the #[Table] attribute function correctly as the universal source of truth for both basic model instances and Pivot model instances alike.