Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set character set by laravel

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to set character set in laravel". In daily operation, I believe many people have doubts about how to set character set in laravel. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to set character set in laravel". Next, please follow the editor to study!

Laravel sets the character set method: 1, open the corresponding code file; 2, use Schema to modify the character set, code such as "Schema::create ('codes', function (Blueprint $table) {{...}}".

This article operating environment: Windows7 system, Laravel5.7 version, Dell G3 computer.

How does laravel set the character set?

Laravel database: modifying field character set

You may encounter some string fields that need to be case-sensitive in a particular environment. The table generated by Schema defaults to utf8_unicode_ci,ci, which means Case Insensitive, so the end of * _ ci is not case-sensitive. We can use Schema to modify the character set during the migration.

Modify the field:

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"); at this point, the study on "how to set the character set in laravel" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report