3

i write composer require laravel/horizon to composer but it give this error :

Your requirements could not be resolved to an installable set of packages.

Problem 1 - Root composer.json requires laravel/horizon ^0.1.0 -> satisfiable by laravel/horizon[v0.1.0]. - laravel/horizon v0.1.0 requires illuminate/contracts ~5.4 -> found illuminate/contracts[v5.4.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require laravel/horizon:*" to figure out if any version is installable, or "composer require laravel/horizon:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

my composer.json :

    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "laravel/framework": "^9.11",
        "laravel/sanctum": "^2.14.1",
        "laravel/tinker": "^2.7"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.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
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
Mehti Sadixov
  • 71
  • 1
  • 6
  • i solved that with this code : composer require laravel/horizon:^v5.9.7 --ignore-platform-req=ext-pcntl --ignore-platform-req=ext-posix – Mehti Sadixov May 12 '22 at 12:18
  • 2
    Why are you trying to require laravel/horizon ^0.1.0? The latest version at this time is 5.9.7. Obviously the old version of horizon requires old dependencies, and those conflict with what you already have installed. Don't specify a version, just do `composer require laravel/horizon` and let Composer detect the appropriate version for you. – jurchiks May 12 '22 at 12:23
  • @jurchiks please read my problem correctly i already use composer require laravel/horizon and it give error : Your requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires laravel/horizon ^0.1.0 -> satisfiable by laravel/horizon[v0.1.0]. - laravel/horizon v0.1.0 requires illuminate/contracts ~5.4 -> found illuminate/contracts[v5.4.0, ..., 5.8.x-dev] but these were not loaded, likely because it conflicts with another require. – Mehti Sadixov May 12 '22 at 13:39
  • 1
    you're not reading what I wrote either. You're trying to require `laravel/horizon ^0.1.0`, which is an ANCIENT version. 0.1.0 was released on Jul 26, 2017. And your `composer.json` does not contain an entry for `laravel/horizon`, so it's apparent you're trying to require it from CLI. Although it could be that your `composer.lock` contains `laravel/horizon` while your .json does not, in which case you should just delete that lock file and rerun `composer install`. – jurchiks May 12 '22 at 14:12

2 Answers2

2

i solved that with this code : composer require laravel/horizon:^v5.9.7 --ignore-platform-req=ext-pcntl --ignore-platform-req=ext-posix

Mehti Sadixov
  • 71
  • 1
  • 6
  • 2
    Your answer does not explain WHY your solution works, not to mention the unnecessary `--ignore-platform-req` parameters which he definitely should not have to use. There's a reason why those extensions are required by the library. – jurchiks May 12 '22 at 12:26
0

When using composer require without a version constraint. It will automatically pick the highest compatible package version for you. Because your PHP installation does not contain the pctnl extension, the latest version that you "can" install is v0.1.0. You can see the extension getting added in v0.2.0 (Commit)

Using the --ignore-platform-reqs flag is a bad practice most of the time. Sure, it will install the package for you. But these extensions are crucial when running Laravel Horizon properly. Ignoring the error is not the correct option here. Please look for a way to install/enable the missing extensions on your system.

The latest laravel/horizon version requires 3 PHP extensions: json, pcntl & posix. I normally

You can check which extensions are installed with the following command:

php -m

Alternatively, you can also check if the extensions are installed by pasting those requirements in the composer.json file and just run composer update to see if you are missing any extensions:

{
  "require": {
    "ext-json": "*",
    "ext-pcntl": "*",
    "ext-posix": "*",
    // Other requirements ...
  }
}
Mark Walet
  • 1,147
  • 10
  • 21