Laravel - custom .env file

前端 未结 6 1854
难免孤独
难免孤独 2020-12-31 19:41

Laravel assumes that .env file should describe environment, and it should not be committed to your repo.

What if I want to keep both .env f

6条回答
  •  隐瞒了意图╮
    2020-12-31 20:10

    Use Dotenv::load() for custom .env file

    laravel 5.1 with vlucas/phpdotenv ~1.0

    if ($_SERVER['HTTP_HOST'] == 'prod.domain.com') {
        Dotenv::load(__DIR__ . '/../','.production.env');
    } else {
        Dotenv::load(__DIR__ . '/../','.dev.env');
    }
    

    OR

    laravel 5.2 with vlucas/phpdotenv ~2.0

    $dotenv = new Dotenv\Dotenv(__DIR__, 'myconfig'); // Laravel 5.2
    $dotenv->load();
    

    PHP dotenv

    In bootstrap/app.php

提交回复
热议问题