Skip to content

Commit 12cbfa5

Browse files
[11.x] Add length to binary method (#50355)
* add length to binary * Update Blueprint.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent ed93be8 commit 12cbfa5

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/Illuminate/Database/Schema/Blueprint.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,11 +1272,13 @@ public function year($column)
12721272
* Create a new binary column on the table.
12731273
*
12741274
* @param string $column
1275+
* @param int|null $length
1276+
* @param bool $fixed
12751277
* @return \Illuminate\Database\Schema\ColumnDefinition
12761278
*/
1277-
public function binary($column)
1279+
public function binary($column, $length = null, $fixed = false)
12781280
{
1279-
return $this->addColumn('binary', $column);
1281+
return $this->addColumn('binary', $column, compact('length', 'fixed'));
12801282
}
12811283

12821284
/**

src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,10 @@ protected function typeYear(Fluent $column)
999999
*/
10001000
protected function typeBinary(Fluent $column)
10011001
{
1002+
if ($column->length) {
1003+
return $column->fixed ? "binary({$column->length})" : "varbinary({$column->length})";
1004+
}
1005+
10021006
return 'blob';
10031007
}
10041008

src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,10 @@ protected function typeYear(Fluent $column)
874874
*/
875875
protected function typeBinary(Fluent $column)
876876
{
877+
if ($column->length) {
878+
return $column->fixed ? "binary({$column->length})" : "varbinary({$column->length})";
879+
}
880+
877881
return 'varbinary(max)';
878882
}
879883

0 commit comments

Comments
 (0)