我是拉维尔的新人.我想使用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.

请注意,我使用PHP8.1.10并下载php_mongob.dll(从this link下载,它支持PHP7.3)到php\ext文件夹,并添加extension=php_mongodb.dllphp.ini文件,但它看起来好像找不到这个模块,如上面的结果所示.

这是我的composer json:

{
    "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
}

我try 了另一个命令,如composer require jenssegers/mongodb:dev-develop --ignore-platform-reqscomposer require jenssegers/mongodb 3.8 --ignore-platform-reqscomposer require jenssegers/mongodb:* --ignore-platform-reqscomposer require jenssegers/mongodb:*或类似的命令,但没有帮助.

我该如何解决这个问题呢? 任何帮助都将不胜感激.

推荐答案

此时此刻,以下是一些问题

  • You are using laravel 10. The jenssegers/mongodb package currently (at the time of writing this answer ) does not have any stable versions that support laravel 10 ( There is a new released planned soon with support for laravel 10, but no release date announced ). So you would need to use their master branch which has added support for laravel 10 ( master branch is still undergoing development, so expect breaking changes ). You can install the master branch code using
    composer require jenssegers/mongodb:dev-master

  • 您使用的是PHP8.1,但您安装的是PHP7.3的MongoDB扩展,它们不兼容.你需要下载一个兼容的版本,最好是1.13版(最新的Windows版本).你可以从这里下载https://pecl.php.net/package/mongodb/1.13.0/windows(请务必下载线程安全版本)

  • jenssegers/mongodb will try to install the latest version of mongodb/mongodb, which requires the PHP extension version 1.15. Unfortunately, version 1.15 is not yet released for windows, so you will have to use version 1.12 of the package which will run on version 1.13 of the extension
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master

  • Now the last issue is that the master branch of jenssegers/mongodb also requires MongoDB extension 1.15. Unfortunately, there's probably no safe way around this. You could run
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
    and get it to install, but it may or may not work in all cases.

所以你有的 Select 是

  1. Use WSL2 or docker to get a linux environment. You can then install the 1.15 version of the PHP extension and you can just run
    composer require jenssegers/mongodb:dev-master
    and get it to work
  2. Stick to windows and downgrade to laravel 9. Then you may run
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb
  3. Ignore the platform requirements and hope that it works and run
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs

希望这能有所帮助

Php相关问答推荐

Laravel—通过单击处理多条路由

未在moodle上运行的计划任务

有什么方法可以阻止WordPress主题升级通知吗?

WooCommerce购物车中仅允许一个可下载产品

WooCommerce产品按特定元数据的自定义数字排序选项

如何在WooCommerce产品子类别中显示特定内容

这是在可召回的背景下吗?

服务器迁移后无法上载文件-可能存在权限问题

Regex|PHP捕获json字符串中的每个非法双引号

使用 PHP,我可以将 foreach 语句放入瞬态中吗?

无法允许元素(img:'src')与symfony html-sanitizer(symfony6.3 php 8.2)

如何用十进制和字母数字减go 和添加 id

如何在laravel中获得两个时间戳之间的小时和分钟差异

使用产品自定义字段作为 WooCommerce 中特定用户角色的折扣百分比

无法使用 slim 的父级容器

Laravel 添加到经过身份验证的用户的数据将应用于每个查询

避免在 WooCommerce 中多次触发挂钩函数

如何在 WooCommerce 中显示每个自定义选项卡的内容

Laravel 10 单元测试看不到来自 Artisan Command 的数据库更改

WordPress 函数 get_post(post_id) 是否查询数据库?