I am trying to write an installer-type app using Laravel 10. Where the purpose is: if I don't set the database information it will redirect me to the setup database. When I fill up the form and submit, it performs the following task:
- Update database-related content in the .env file
- Clear cache, config, and finally cache new config using the
Artisancall. - Finally migrate the database still using the
Artisancall.
Although the .env file content is updated, it still uses the last database-related info that existed before the update. I mean, suppose previously DB name was ab_setup, then I update it to nn_setup, .env file shows the DB name as nn_setup, but the browser responds:
Unknown database
ab_setup(Connection: mysql, SQL: select * from information_schema.tables where table_schema = nn_setup and table_name = migrations and table_type = 'BASE TABLE').
I have no idea what's actually wrong. Here is my code:
// Update .env file content
$envContent = [
'DB_CONNECTION' => $request->database_connection,
'DB_HOST' => $request->database_host,
'DB_PORT' => $request->database_port,
'DB_DATABASE' => $request->database_name,
'DB_USERNAME' => $request->database_username,
'DB_PASSWORD' => $request->database_password
];
foreach( $envContent as $key => $value ) {
$this->replace_env_value($key, $value);
}
// Clear Cache and Config & Cache new Config
Artisan::call('cache:clear');
Artisan::call('config:clear');
Artisan::call('config:cache');
// Migrate DB and Seed
Artisan::call('migrate');
Artisan::call('db:seed');
// Create Admin User
$user = new User();
$user->name = $request->admin_name;
$user->email = $request->admin_username;
$user->password = Hash::make($request->admin_password);
$user->save();
Does anyone have the idea what I miss that will fix the issue?
.envvalues are passed to Laravel'sconfig(), likeconfig('database'); I wonder if that is being "sticky", despite the call toconfig:clear🤔 If you dodd(config('database.connections.' . config('database.default')))following that artisan call, do you see the old or new values?