在 Laravel 7 的特使脚本中获取 Dotenv 值

Getting Dotenv values in envoy script in Laravel 7

通常在我的 Envoy.blade.php 文件中,我首先设置变量...

@include('./vendor/autoload.php');

@setup
    $dotenv = Dotenv\Dotenv::create(__DIR__);
    try {
        $dotenv->load();
        $dotenv->required(['DEPLOY_PATH'])->notEmpty();
    } catch ( Exception $e )  {
        echo $e->getMessage();
    }
@endsetup

当我 运行 envoy run deploy 我得到以下错误。

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Dotenv\Dotenv::create() must be an instance of Dotenv\Repository\RepositoryInterface, string given, called in /Users/khill5/Sites/interpreter/Envoyd538ebf09581d7d4e66c810d4e2dd41c.php on line 16 and defined in /Users/khill5/Sites/interpreter/vendor/vlucas/phpdotenv/src/Dotenv.php:62

发生了什么变化?

我想通了。

@setup
    $dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
    try {
        $dotenv->load();
        $dotenv->required(['DEPLOY_PATH'])->notEmpty();
    } catch ( Exception $e )  {
        echo $e->getMessage();
    }
@endsetup