diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasUlids.php b/src/Illuminate/Database/Eloquent/Concerns/HasUlids.php index 0c3417485a2c..bc80745b367b 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasUlids.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasUlids.php @@ -55,4 +55,18 @@ public function getKeyType() return $this->keyType; } + + /** + * Get the value indicating whether the IDs are incrementing. + * + * @return bool + */ + public function getIncrementing() + { + if (in_array($this->getKeyName(), $this->uniqueIds())) { + return false; + } + + return $this->incrementing; + } } diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasUuids.php b/src/Illuminate/Database/Eloquent/Concerns/HasUuids.php index 7049dee4ae3d..0f28bd08212f 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasUuids.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasUuids.php @@ -55,4 +55,18 @@ public function getKeyType() return $this->keyType; } + + /** + * Get the value indicating whether the IDs are incrementing. + * + * @return bool + */ + public function getIncrementing() + { + if (in_array($this->getKeyName(), $this->uniqueIds())) { + return false; + } + + return $this->incrementing; + } } diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 3cfa33fe1a91..14d6137c4421 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -1851,10 +1851,6 @@ public function setKeyType($type) */ public function getIncrementing() { - if ($this->getKeyType() === 'string') { - return false; - } - return $this->incrementing; } diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index a62492ee0be4..d9b71e663a96 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -2216,10 +2216,9 @@ public function testIntKeyTypePreserved() public function testStringKeyTypePreserved() { $model = $this->getMockBuilder(EloquentKeyTypeModelStub::class)->onlyMethods(['newModelQuery', 'updateTimestamps', 'refresh'])->getMock(); - $model->id = 'string id'; $query = m::mock(Builder::class); - $query->shouldReceive('insert')->once()->with(['id' => 'string id']); + $query->shouldReceive('insertGetId')->once()->with([], 'id')->andReturn('string id'); $query->shouldReceive('getConnection')->once(); $model->expects($this->once())->method('newModelQuery')->willReturn($query);