Online Snippets Library

How to set up environment configuration In Laravel

One Application deployed in various environments like local,staging and production.Each of these environments may have different configuration and setting.In laravel we can easily handle it.

Setting Environments

Open up the "bootstrap/start.php".Here we define our environments for the application.Each key in this array is the name of an environment and the corresponding value is an array of URLs that will match this environment.

$env = $app->detectEnvironment(function(){
    $host = @$_SERVER['HTTP_HOST'];
    switch ($host){
        case 'local.tutsway.com':
            return 'local';
        case 'dev.tutsway.com':
            return 'develop';
        case 'staging.tutsway.com':
            return 'staging';
        case 'www.tutsway.com':
            return 'production';
    }
});

Accessing Current Application Environments

We can access the current application environment via the environment method.

$environment = $app->environment();

We can also pass arguments to the environment method to check if the environment matches a given value or not.

if ($app->environment('local'))
{
    // local setting
}
if ($app->environment('local', 'staging'))
{
    //  local and staging setting
}

remove-index.php-from-url-in-codeigniter