简体   繁体   中英

How do i change database name in Laravel?? I already changed database in config/database.php and .env

How to change database name in Laravel? I already made changes in config/database.php and .env file. I need database name as scoolmgmt Config/database.php

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'scoolmgmt'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

**Routes.php**
Route::get('/dbname', function(){
    return DB::getDatabaseName();
});

Output is:- laravel

Caching stores the configured values from the config files. You can clear the Cache with the following artisan command php artisan config:clear

After your change you can make a new cache file with the command php artisan config:cache

type in project terminal

php artisan config:cache

Your database will definitely get updated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM