Laravel is not detecting my local database configuration file (development)

My Laravel app is running on my local machine. When I run my application, Laravel uses my production database configuration and throws an exception:

SQLSTATE[HY000] [1045] Access denied for user 'production_admin'@'localhost' (using password: YES)


This is weird because when I check the current environment with artisan

, it says:

Current application environment: development


and my database config file development

has a different username and password.

also i said in bootstrap/start.php


$env = $app->detectEnvironment(array(
    'development' => array('*.dev', gethostname()),
    'production' => array('*.com', '*.net', '*.org', '*.ir')


I don't know why Laravel insists on using config production

even though I'm in the environment development


Thank you for your help.


source to share

1 answer

The best way to avoid this problem is to do the following:

in /bootstrap/start.php

Replace the default environment detection with:

$env = $app->detectEnvironment(function()
    return getenv('APP_ENV') ?: 'local';


This will check for an environment variable that is set by apache / nginx, assuming you are running Homestead or similar.



All Articles