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
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