Laravel 5 : Use different database for testing and local

后端 未结 6 1478
栀梦
栀梦 2020-12-24 12:21

How does one change database for development and testing on local system without editing the .env file each time?

I have found it quite inconvenient to

6条回答
  •  清歌不尽
    2020-12-24 12:36

    For Laravel 5.5, the proper way to do this is create a testing environment file called .env.testing. Here, you can define your testing environment, including the database you want to use for testing...

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=test DB
    DB_USERNAME=test DB user
    DB_PASSWORD=test DB password
    

    Then run this command...

    php artisan config:cache --env=testing
    

    This will configure the cache to the .env.testing file parameters.

    Here is a link to the documentation.

提交回复
热议问题