Monday, 23 October 2017

How to change Laravel database configuration

Step 1: Locate the .env File

Laravel uses environment files (.env) to manage configuration settings, making it easy to switch environments without altering code. The .env file is where you'll define your database connection details. Navigate to the root directory of your Laravel project and find the .env file.

Step 2: Edit Database Configuration Settings

Open the .env file in your preferred text editor. You will see several database configuration options, including:


DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laradb
DB_USERNAME=root
DB_PASSWORD=root

Here is a screenshot with database setting.

Step 3: Clear Configuration Cache

After making changes to your .env file, it's essential to clear your application's configuration cache to apply the changes. Run the following command in your terminal:


php artisan config:clear

This command ensures that Laravel loads the new database configuration settings.

Step 4: Test the New Database Connection

To test our database setting we need to run the following command.


php artisan migrate


In case of any error always make sure to add exact database details in .env file

No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...