Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel/Lumen迁移:如何创建永久大写列?_Php_Sql_Laravel_Database Migration_Lumen - Fatal编程技术网

Php Laravel/Lumen迁移:如何创建永久大写列?

Php Laravel/Lumen迁移:如何创建永久大写列?,php,sql,laravel,database-migration,lumen,Php,Sql,Laravel,Database Migration,Lumen,我的Laravel迁移如下所示: class CreateTableLanguage extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('language', function (Blueprint $table) { $table-&g

我的Laravel迁移如下所示:

class CreateTableLanguage extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('language', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->char('iso639_1',2)->unique()->comment('http://www.loc.gov/standards/iso639-2/php/code_list.php');
            $table->char('locale',2)->uppercase();  // DUMMY uppercase(), does not work
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('language');
    }
}
在SQL中,我可以使用以下语句强制列的内容为大写:

UPDATE
  MyTable
SET
  MyColumn = UPPER(MyColumn)

如何将大写字母应用于我的Laravel migrations类?

在Laravel中,您可以使用

这样,当您尝试使用Laravel修改该字段时,您将以大写形式存储该值

$language->locale = 'es'; // this will be 'ES'
$language->save();
为了补充这种行为,如果您希望确保在其他人手动或使用自定义代码添加记录时始终以大写形式获取值,则可以创建访问器

public function getLocaleAttribute($value)
{
    return strtoupper($value);
}

在Laravel中,您可以使用

这样,当您尝试使用Laravel修改该字段时,您将以大写形式存储该值

$language->locale = 'es'; // this will be 'ES'
$language->save();
为了补充这种行为,如果您希望确保在其他人手动或使用自定义代码添加记录时始终以大写形式获取值,则可以创建访问器

public function getLocaleAttribute($value)
{
    return strtoupper($value);
}

是的,我想你要么做这个,要么写个触发器。是的,我想你要么做这个,要么写个触发器。