编辑:
AppServiceProvider
文件/类、boot()
函数内执行。我正在尝试将 sail 安装到我的克隆项目中。我正在使用官方文档中的脚本:
(请注意,如下面编辑的部分所示)该错误是由于驻留在
$categories = Category::all()->where('active', true);
类中的 boot()
函数中的这一行 AppProviderService
引起的。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
函数解决了它,但是不注释代码的修复是什么...
执行
install
时,composer将执行post-install-cmd
脚本。
https://getcomposer.org/doc/articles/scripts.md#installer-events
您的项目似乎在某种程度上配置错误,因此在执行安装后脚本时它将失败。
您可以修复项目设置(这样运行时不会失败
install
),或者简单地将 --no-scripts
传递给 install
,这样这些脚本就不会被执行。
但请注意,您稍后可能需要手动运行这些脚本,因为它们可能会执行一些家务活。了解项目及其运行堆栈通常是一个好主意。