Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# v8.3.0 (2024-09-02)

- add support for invisible columns (#240)
- add support for change streams using Blueprint (#230)
- add support for snapshot queries (#215)
- deprecate Connection::getDatabaseContext() and move logic to UseMutations::getMutationExecutor() (#227)
Expand Down
17 changes: 16 additions & 1 deletion src/Schema/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Illuminate\Contracts\Database\Query\Expression as ExpressionContract;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\ColumnDefinition;
use Illuminate\Database\Schema\Grammars\Grammar as BaseGrammar;
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
Expand All @@ -38,7 +39,7 @@ class Grammar extends BaseGrammar
/**
* @inheritdoc
*/
protected $modifiers = ['Nullable', 'Default', 'UseSequence'];
protected $modifiers = ['Nullable', 'Default', 'Invisible', 'UseSequence'];

/**
* Compile the query to determine the tables.
Expand Down Expand Up @@ -733,6 +734,20 @@ protected function typeBoolean(Fluent $column)
return 'bool';
}

/**
* Get the SQL for an invisible column modifier.
*
* @param Blueprint $blueprint
* @param ColumnDefinition&object{ invisible: bool } $column
* @return string|null
*/
protected function modifyInvisible(Blueprint $blueprint, Fluent $column)
{
return $column->invisible !== null
? ' hidden'
: null;
}

/**
* @param Blueprint $blueprint
* @param IntColumnDefinition $column
Expand Down
24 changes: 24 additions & 0 deletions tests/Schema/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,30 @@ public function test_composite_primary_key(): void
], $statements);
}

public function test_invisible_columns(): void
{
$conn = $this->getDefaultConnection();
$grammar = new Grammar();
$tableName = $this->generateTableName('Invisible');

$blueprint = new Blueprint($tableName, function (Blueprint $table) {
$table->create();
$table->integer('id')->primary();
$table->string('name')->nullable()->invisible();
});

$this->assertSame([
"create table `{$tableName}` (`id` int64 not null, `name` string(255) hidden) primary key (`id`)",
], $blueprint->toSql($conn, $grammar));

$blueprint->build($conn, $grammar);

$conn->table($tableName)->insert(['id' => 1, 'name' => 'test']);
$row = $conn->table($tableName)->first();
$this->assertArrayHasKey('id', $row);
$this->assertArrayNotHasKey('name', $row);
}

public function test_interleaving(): void
{
$conn = $this->getDefaultConnection();
Expand Down