-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Closed
Description
Laravel Version
13.1.1
PHP Version
8.5.2
Database Driver & Version
No response
Description
The #[Table] attribute includes an argument to specify whether the primary key should be incrementing, in favor of the old property style declaration.
Pivot models are set to non-incrementing by default:
framework/src/Illuminate/Database/Eloquent/Relations/Pivot.php
Lines 8 to 17 in 8aa511e
| class Pivot extends Model | |
| { | |
| use AsPivot; | |
| /** | |
| * Indicates if the IDs are auto-incrementing. | |
| * | |
| * @var bool | |
| */ | |
| public $incrementing = false; |
Using #[Table] to configure that a Pivot model should still be incrementing however doesn't work out. The $incrementing property in parent Pivot class still takes precedence and prevents the attribute's incrementing argument from actually firing:
framework/src/Illuminate/Database/Eloquent/Model.php
Lines 449 to 455 in 8aa511e
| if ($this->incrementing === true) { | |
| if (static::resolveClassAttribute(WithoutIncrementing::class) !== null) { | |
| $this->incrementing = false; | |
| } elseif ($table && $table->incrementing !== null) { | |
| $this->incrementing = $table->incrementing; | |
| } | |
| } |
Steps To Reproduce
#[Table(incrementing: true)]
class MyModel extends Pivot {}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.