Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include custom config for different environment in Laravel-4

$env = $app->detectEnvironment(array(

    'local' => array('*.local'),

));

The original config files can be used in my local environment like the database.php, cache.php etc. But my custom config isn't getting used in my local environment.

Is there a way to add my custom config on it?

like image 637
Ironwind Avatar asked Jul 16 '13 08:07

Ironwind


People also ask

How do I override a configuration file in Laravel?

Laravel stores all the config file values into one single array. So, the "Laravel way" of overwriting the config variables after they are set is to edit the array in which they are stored: config([ // overwriting values set in config/app. php 'app.

What is use of .ENV in Laravel?

Laravel's default .env file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the config directory using Laravel's env function.

Where is .ENV file in Laravel?

In your main Laravel folder you should have . env file which contains various settings, one row – one KEY=VALUE pair. And then, within your Laravel project code you can get those environment variables with function env('KEY').

What is config () in Laravel?

What is the config method? The config method allows your application to get or set values in all files that are in the config directory.


2 Answers

If you are on Linux and Mac, you may determine your "hostname" using the "hostname" terminal command and use it in the array.

like image 29
Edwin M Avatar answered Oct 07 '22 06:10

Edwin M


First, you need to define, what is 'local' environment

$env = $app->detectEnvironment(array(
    // everything that contains 'localhost' or '127.0.0.1'
    // in URL will be considered to run in local env.
    'local' => array('localhost', '127.0.0.1'),

));

Then, you need to create directory named local in app/config. If you want to override DB settings in local env. create the file: app/config/local/database.php and override setting in this file, for example:

'connections' => array(

    'mysql' => array(
        'username'  => 'otherUserName',
        'password'  => 'otherPassword',
    ),

), 

In this file, you do not need to specify all options, only options that are different from production/base configuration.

More info in official docs

like image 194
Andreyco Avatar answered Oct 07 '22 05:10

Andreyco