我是Laravel的新手。我想使用Laravel 10连接到MongoDB,这需要安装jenssegers/mongodb。当我在终端中运行命令composer require jenssegers/mongodb 3.8.0 --ignore-platform-reqs
时,我收到如下错误:
PHP Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: D:\ProgramFiles\xampp\php\ext\php_mongodb.dll (The specified module could not be found), D:\ProgramFiles\xampp\php\ext\php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: D:\ProgramFiles\xampp\php\ext\php_mongodb.dll (The specified module could not be found), D:\ProgramFiles\xampp\php\ext\php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0
Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
Running composer update jenssegers/mongodb
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires jenssegers/mongodb 3.8.0 -> satisfiable by jenssegers/mongodb[v3.8.0].
- jenssegers/mongodb v3.8.0 requires illuminate/support ^8.0 -> found illuminate/support[v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
请注意,我使用PHP 8.1.10和下载php_mongodb. dll(从this link下载,它支持PHP 7.3)到php\ext
文件夹,并添加extension=php_mongodb.dll
到php.ini
文件,但它看起来像这个模块无法找到,如上面的结果所示。
这是我的 composer
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.2"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
我尝试了另一个命令,如composer require jenssegers/mongodb:dev-develop --ignore-platform-reqs
,composer require jenssegers/mongodb 3.8 --ignore-platform-reqs
,composer require jenssegers/mongodb:* --ignore-platform-reqs
,composer require jenssegers/mongodb:*
或类似的,但它没有帮助。
我该怎么解决这个问题呢?任何帮助都将不胜感激。
1条答案
按热度按时间jmp7cifd1#
现在,问题是
jenssegers/mongodb
软件包当前(在撰写此答案时)没有任何支持laravel 10的稳定版本(有一个新的发布计划很快与支持laravel 10,但没有发布日期宣布)。所以你需要使用他们的主分支,其中增加了对laravel 10的支持(master分支仍在开发中,因此预计会有重大更改)。您可以使用以下命令安装master分支代码composer require jenssegers/mongodb:dev-master
jenssegers/mongodb
将尝试安装最新版本的mongodb/mongodb
,这需要PHP扩展版本1.15。遗憾的是,尚未针对Windows发布版本1.15,因此您必须使用将在版本1.13的扩展上运行的版本1.12的软件包composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master
jenssegers/mongodb
的master分支也需要MongoDB扩展1.15。不幸的是,可能没有安全的方法来解决这个问题。composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
并让它安装,但它可能会或可能不会在所有情况下工作。
所以你的选择是
1.使用WSL2或Docker获得Linux环境,然后安装1.15版本的PHP扩展,只需运行
composer require jenssegers/mongodb:dev-master
让它发挥作用
1.坚持windows,降级到laravel 9,然后你可以运行
composer require mongodb/mongodb:^1.12 jenssegers/mongodb
1.忽略平台要求,希望它能正常工作和运行
composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
希望这能帮上忙