Skip to content

Fix Table attribute incrementing not working for Pivot models#59336

Merged
taylorotwell merged 2 commits intolaravel:13.xfrom
sadique-cws:fix-table-incrementing-pivot
Mar 23, 2026
Merged

Fix Table attribute incrementing not working for Pivot models#59336
taylorotwell merged 2 commits intolaravel:13.xfrom
sadique-cws:fix-table-incrementing-pivot

Conversation

@sadique-cws
Copy link
Contributor

@sadique-cws sadique-cws commented Mar 23, 2026

Description

Fixes #59335

This PR solves an issue where using the #[Table] attribute on a Pivot model fails to configure its incrementing primary key property correctly. For regular model classes, the incrementing argument 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:

class Pivot extends Model {
    public $incrementing = false; // <-- Default false for Pivot
}

Inside Illuminate\Database\Eloquent\Model::__construct, there exists logic that attempts to sync attributes from #Table classes, but includes an isolated safeguard:

php

if ($this->incrementing === true) { // <-- ❌ Blocks override for values that start as false
     $this->incrementing = $tableAttribute->incrementing;
}

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.

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.
@taylorotwell taylorotwell merged commit 05e550d into laravel:13.x Mar 23, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incrementing argument in Table attribute doesn't work for Pivot models

2 participants