gpt4 book ai didi

mysql - Laravel 架构生成器 : Creating a binary(16) column

转载 作者:行者123 更新时间:2023-12-01 08:47:53 31 4
gpt4 key购买 nike

使用 Laravel 5.5 和 Mysql (10.1.19-MariaDB)

对于 md5 哈希,我想要一个 binary(16) 列。
让我们调用专栏 url_hash

使用时:

$table->binary('url_hash');

它会给我一个 BLOB 列。

来源: https://laravel.com/docs/5.5/migrations#creating-columns

我已经在网络上看到了各种针对此的黑客或插件,但是没有任何可能在下次更新时中断的外部插件的最简单的方法是什么?

干杯

最佳答案

扩展 MySqlGrammar类,例如在 app/MySqlGrammar.php :

namespace App;

use Illuminate\Support\Fluent;

class MySqlGrammar extends \Illuminate\Database\Schema\Grammars\MySqlGrammar {

protected function typeRealBinary(Fluent $column) {
return "binary({$column->length})";
}

}

然后使用宏添加您自己的列类型:
DB::connection()->setSchemaGrammar(new \App\MySqlGrammar());

Blueprint::macro('realBinary', function($column, $length) {
return $this->addColumn('realBinary', $column, compact('length'));
});

Schema::create('table', function(Blueprint $table) {
$table->realBinary('url_hash', 16);
});

关于mysql - Laravel 架构生成器 : Creating a binary(16) column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49389233/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com