Ad

.gitignore The Database File In Laravel

- 1 answer

I'm sharing my Laravel project with another co-worker. But he's using Mac and I'm using Windows. So there's specific change to his database.php file which is only for Mac mamp. How can I ignore this file from the version controlling? Should I add this file path in the .gitignore at the root directory?

Ad

Answer

For configs I use .env.development.php. my file looks like the following

<?php
  return [
  'ENV'             => 'development',
  'DB_USERNAME' => 'db_dev_username',
  'DB_PASSWORD' => 'db_password',
  'DB_NAME'          => 'dev_db'
];

Inside this file I have my database settings. then I create /app/config/development folder. inside that is settings i want running. I would have a database.php file in there and it looks like

return array(
    'connections' => array(
       'mysql' => array(
           'driver'    => 'mysql',
           'host'      => getenv('DB_HOST'),
           'database'  => getenv('DB_NAME'),
           'username'  => getenv('DB_USERNAME'),
           'password'  => getenv('DB_PASSWORD'),
           'charset'   => 'utf8',
           'collation' => 'utf8_unicode_ci',
           'prefix'    => '',
        ),
    ),
);

/bootstrap/start.php - it has this inside it. if it can't find the value of ENV, it defaults to development.

$env = $app->detectEnvironment(function()
{
    return getenv('ENV') ?: 'development';
});

laravel should come with .gitignore that includes an entry for the .env.* files so it won't push it.

my .gitignore file looks like this:

/bootstrap/compiled.php
/vendor
composer.phar
composer.lock
.DS_Store 
Thumbs.db
app/config/local
app/config/development
.env.*.php
Ad
source: stackoverflow.com
Ad