【问题标题】:Integration of Laravel in existing project throwing errorLaravel 在现有项目中的集成引发错误
【发布时间】:2022-02-23 13:10:45
【问题描述】:

我创建了一个直接的 laravel 项目,只是样板文件。当我使用风帆指南 (https://laravel.com/docs/9.x/sail#installation) 时,我运行 composer require laravel/sail --dev 并且运行良好,但是当我执行 php artisansail:install 时出现此错误:

ErrorException 

  file_get_contents(/home/michaelb/Desktop/scouting/.env): Failed to open stream: No such file or directory

  at vendor/laravel/sail/src/Console/InstallCommand.php:125
    121▕      * @return void
    122▕      */
    123▕     protected function replaceEnvVariables(array $services)
    124▕     {
  ➜ 125▕         $environment = file_get_contents($this->laravel->basePath('.env'));
    126▕ 
    127▕         if (in_array('pgsql', $services)) {
    128▕             $environment = str_replace('DB_CONNECTION=mysql', "DB_CONNECTION=pgsql", $environment);
    129▕             $environment = str_replace('DB_HOST=127.0.0.1', "DB_HOST=pgsql", $environment);

      +15 vendor frames 
  16  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

这是在选择我想要 pgsql 数据库之后。我该怎么做才能解决这个问题?

【问题讨论】:

    标签: php laravel docker


    【解决方案1】:

    您是否在项目文件夹中运行了以下命令?

    sail up
    

    这将使用 docker 为您创建并准备好项目。

    主要错误是您的项目中没有 .env 文件。您可以将 .env.example 复制并粘贴到 .env 文件中。它会解决你的问题。

    您必须在容器中运行 composer install 命令。不在你的本地机器上。但是,我认为您错过了几个步骤,因为 laravel 应该为您创建 .env 文件。

    【讨论】:

      【解决方案2】:

      你得到一个错误,因为你的项目中缺少供应商文件夹,你需要 /vendor 因为你所有的包都在那里,包括 Laravel 使用的所有类。供应商目录包含您的 Composer 依赖项。

      执行此步骤后可以解决您的问题。你可以试试:

      composer update --no-scripts 
      composer update
      

      使用此命令,您将在项目中重新创建供应商文件夹,之后您的项目将开始正常工作。

      这个答案在这个链接上给出

      https://stackoverflow.com/questions/54033140/failed-opening-autoload-php-in-laravel-5 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-27
        • 1970-01-01
        • 2018-02-13
        • 2021-03-13
        • 2012-02-05
        相关资源
        最近更新 更多