Search code examples
phplaravellaravel-7laravel-envoy

Getting Dotenv values in envoy script in Laravel 7


Typically in my Envoy.blade.php file, I first set up the variables...

@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

When I run envoy run deploy I get the following error.

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

What has changed?


Solution

  • I figured it out.

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