例如:表前缀为“prefix”,用户表全名为“prefix_users”。
则进入项目文件夹“config”->“database.php”内:
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
.......以下省略
找到这一行:
'prefix' => '',
将其改为:
'prefix' => env('DB_PREFIX', ''),
在进入项目根目录下的".env"文件中,找到这一区块,在其下方添加DB_PREFIX=prefix_ 即可
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=demo
DB_USERNAME=root
DB_PASSWORD=root
DB_PREFIX=prefix_