Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add invisible modifier for MySQL columns #40002

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Illuminate/Database/Schema/ColumnDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @method $this from(int $startingValue) Set the starting value of an auto-incrementing field (MySQL / PostgreSQL)
* @method $this generatedAs(string|Expression $expression = null) Create a SQL compliant identity column (PostgreSQL)
* @method $this index(string $indexName = null) Add an index
* @method $this invisible() Specify that the column should be invisible to "SELECT *" (MySQL)
* @method $this nullable(bool $value = true) Allow NULL values to be inserted into the column
* @method $this persisted() Mark the computed generated column as persistent (SQL Server)
* @method $this primary() Add a primary index
Expand Down
16 changes: 15 additions & 1 deletion src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MySqlGrammar extends Grammar
* @var string[]
*/
protected $modifiers = [
'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable',
'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable', 'Invisible',
'Srid', 'Default', 'Increment', 'Comment', 'After', 'First',
];

Expand Down Expand Up @@ -1038,6 +1038,20 @@ protected function modifyNullable(Blueprint $blueprint, Fluent $column)
}
}

/**
* Get the SQL for an invisible column modifier.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column
* @return string|null
*/
protected function modifyInvisible(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->invisible)) {
return ' invisible';
}
}

/**
* Get the SQL for a default column modifier.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ public function testAddingGeneratedColumnWithCharset()
$this->assertSame('alter table `links` add `url` varchar(2083) character set ascii not null, add `url_hash_virtual` varchar(64) character set ascii as (sha2(url, 256)), add `url_hash_stored` varchar(64) character set ascii as (sha2(url, 256)) stored', $statements[0]);
}

public function testAddingInvisibleColumn()
{
$blueprint = new Blueprint('users');
$blueprint->string('secret', 64)->nullable(false)->invisible();
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table `users` add `secret` varchar(64) not null invisible', $statements[0]);
}

public function testAddingString()
{
$blueprint = new Blueprint('users');
Expand Down