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

How to set character set in laravel

藏色散人
Release: 2021-12-21 11:18:25
Original
2415 people have browsed it

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');
    // ......
});
Copy after login

Or modify the table:

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

Native statement:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template