为什么在新克隆的项目上安装新依赖项时会出现运行时错误?

问题描述 投票:0回答:1

编辑:

  1. 错误是因为执行了我在项目中编写的php代码。
  2. 这是我网站内的查询,安装程序根本没有理由执行它。
  3. 这是一个 laravel&composer 设置问题,但我不知道它的来源和原因。
  4. 在我的 Laravel 项目中,我编写了一个获取类别的查询,代码在默认的 Laravel 本机
    AppServiceProvider
    文件/类、
    boot()
    函数内执行。
  5. 在安装完成之前代码无法工作,因为我什至没有数据库......安装程序没有理由执行它。

我正在尝试将 sail 安装到我的克隆项目中。我正在使用官方文档中的脚本:

(请注意,如下面编辑的部分所示)该错误是由于驻留在

$categories = Category::all()->where('active', true);
类中的
boot()
函数中的这一行
AppProviderService
引起的。
我根本不明白为什么在安装composer依赖项时执行代码......

docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs

但是,它失败并出现以下错误:

Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Nothing to install, update or remove Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   Illuminate\Database\QueryException

  could not find driver (SQL: select * from `categories`)

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {   ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

  1   [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(App\Providers\AppServiceProvider))

      +20 vendor frames   22  app/Providers/AppServiceProvider.php:33
      Illuminate\Database\Eloquent\Model::all() Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

注释

boot()
中的
AppServiceProvider
函数解决了它,但是不注释代码的修复是什么...

php composer-php laravel-8
1个回答
0
投票

执行

install
时,composer将执行
post-install-cmd
脚本。

https://getcomposer.org/doc/articles/scripts.md#installer-events

您的项目似乎在某种程度上配置错误,因此在执行安装后脚本时它将失败。

您可以修复项目设置(这样运行时不会失败

install
),或者简单地将
--no-scripts
传递给
install
,这样这些脚本就不会被执行。

但请注意,您稍后可能需要手动运行这些脚本,因为它们可能会执行一些家务活。了解项目及其运行堆栈通常是一个好主意。

© www.soinside.com 2019 - 2024. All rights reserved.