Skip to content

Commit

Permalink
[11.x] Add length to binary method (#50355)
Browse files Browse the repository at this point in the history
* add length to binary

* Update Blueprint.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
hafezdivandari and taylorotwell authored Mar 4, 2024
1 parent ed93be8 commit 12cbfa5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -1272,11 +1272,13 @@ public function year($column)
* Create a new binary column on the table.
*
* @param string $column
* @param int|null $length
* @param bool $fixed
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function binary($column)
public function binary($column, $length = null, $fixed = false)
{
return $this->addColumn('binary', $column);
return $this->addColumn('binary', $column, compact('length', 'fixed'));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ protected function typeYear(Fluent $column)
*/
protected function typeBinary(Fluent $column)
{
if ($column->length) {
return $column->fixed ? "binary({$column->length})" : "varbinary({$column->length})";
}

return 'blob';
}

Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,10 @@ protected function typeYear(Fluent $column)
*/
protected function typeBinary(Fluent $column)
{
if ($column->length) {
return $column->fixed ? "binary({$column->length})" : "varbinary({$column->length})";
}

return 'varbinary(max)';
}

Expand Down

0 comments on commit 12cbfa5

Please sign in to comment.