Home  >  Article  >  PHP Framework  >  How to set character set in laravel

How to set character set in laravel

藏色散人
藏色散人Original
2021-12-21 11:18:252332browse

How to set the character set in laravel: 1. Open the corresponding code file; 2. Use Schema to modify the character set, the code is such as "Schema::create('codes', function (Blueprint $table) {{ ...}}".

How to set character set in laravel

The operating environment of this article: Windows 7 system, Laravel version 5.7, Dell G3 computer.

How to set the character set in laravel?

Laravel database: modify the field character set

In certain environments, you may encounter some string fields that require case distinction , the table generated through Schema defaults to utf8_unicode_ci, ci means Case Insensitive, so anything ending in *_ci is not case-sensitive. We can use Schema to modify the character set during migration.

Modify fields:

Schema::create('codes', function (Blueprint $table) {
{
    // ......
    $table->string('key')->unique()->charset('utf8')->collation('utf8_bin');
    // ......
});

Or modify the table:

Schema::create('codes', function (Blueprint $table) {
    $table->charset = 'utf8';
    $table->collation = 'utf8_bin';
    // ......
});

Native statement:

DB::statement("ALTER TABLE codes CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin");

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of How to set character set in laravel. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn