diff --git a/src/Illuminate/Database/Schema/Builder.php b/src/Illuminate/Database/Schema/Builder.php index 51b97f690618..0fcaef79d2df 100755 --- a/src/Illuminate/Database/Schema/Builder.php +++ b/src/Illuminate/Database/Schema/Builder.php @@ -267,10 +267,15 @@ public function hasColumn($table, $column) * * @param string $table * @param array $columns + * @param bool $strict * @return bool */ - public function hasColumns($table, array $columns) + public function hasColumns($table, array $columns, bool $strict = false) { + if ($strict){ + return $this->getColumnListing($table) === $columns; + } + $tableColumns = array_map('strtolower', $this->getColumnListing($table)); foreach ($columns as $column) { diff --git a/tests/Database/DatabaseSchemaBuilderTest.php b/tests/Database/DatabaseSchemaBuilderTest.php index e2619c667447..d7d50fec7c7f 100755 --- a/tests/Database/DatabaseSchemaBuilderTest.php +++ b/tests/Database/DatabaseSchemaBuilderTest.php @@ -65,10 +65,15 @@ public function testTableHasColumns() $grammar = m::mock(stdClass::class); $connection->shouldReceive('getSchemaGrammar')->andReturn($grammar); $builder = m::mock(Builder::class.'[getColumnListing]', [$connection]); - $builder->shouldReceive('getColumnListing')->with('users')->twice()->andReturn(['id', 'firstname']); + $builder->shouldReceive('getColumnListing')->with('users')->times(6)->andReturn(['id', 'firstname']); $this->assertTrue($builder->hasColumns('users', ['id', 'firstname'])); $this->assertFalse($builder->hasColumns('users', ['id', 'address'])); + + $this->assertTrue($builder->hasColumns('users',['id','firstname'],true)); + $this->assertFalse($builder->hasColumns('users',['id'],true)); + $this->assertFalse($builder->hasColumns('users',['firstname','id'],true)); + $this->assertFalse($builder->hasColumns('users',['id','FirstName'],true)); } public function testGetColumnTypeAddsPrefix()