Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pixelpeter's avatar

Restrict package to specific Laravel versions not working

I need your help please, because I spent several days now and was not able to figure it out by myself.

I have a Laravel package I want to support multiple Laravel version with. Laravel 8 and 9 on php 8.0, 8.1, 8.2 should use the latest version from the 8.x branch => 8.2.0 Laravel 10 and 11 on php 8.1, 8.2, 8.3 should use the latest version from the 10.x branch => 10.1.0

Unfortunately I can not make it work as I have a lot of versions mismatches (see table below). I'm not knowing if I'm doing the definition of the dependencies wrong or if this is caused by a screwed up older published version.

Will it help to delete the falsy releases from the repository (which is normally not recommended)?

Very thankful for everyone pointing me into the right direction.

Here are excerpts from the different composer.json

Here are the results I'm getting.

php laravel expected laravel/framework version correct
8.0 8 8.2.0 8.83.27 8.2.0 YES
8.1 8 8.2.0 8.83.27 8.2.0 NO
8.2 8 8.2.0 8.83.27 10.0.0 NO
8.0 9 8.2.0 9.52.16 8.2.0 YES
8.1 9 8.2.0 9.52.16 10.0.0 NO
8.2 9 8.2.0 9.52.16 10.0.0 NO
8.1 10 10.1.0 10.48.22 10.1.0 YES
8.2 10 10.1.0 10.48.22 10.1.0 YES
8.3 10 10.1.0 10.48.22 10.1.0 YES
8.2 11 10.1.0 11.27.2 8.0.2 NO
8.3 11 10.1.0 11.27.2 8.0.2 NO
0 likes
2 replies
LaryAI's avatar
Level 58

To address the issue of restricting your Laravel package to specific Laravel and PHP versions, you need to ensure that your composer.json files are correctly specifying the dependencies for each version of your package. Here are some steps and tips to help you resolve the mismatches:

  1. Check Version Constraints: Ensure that the version constraints in your composer.json files are correctly defined. The constraints should match the PHP and Laravel versions you intend to support.

  2. Use conflict Section: You can use the conflict section in your composer.json to explicitly specify which versions of Laravel or PHP your package does not support. This can help prevent Composer from resolving to an incorrect version.

  3. Review Composer's Version Resolution: Composer resolves dependencies based on the constraints provided. If there are multiple versions of your package that satisfy the constraints, Composer might choose a version you didn't expect. You can use the prefer-stable and minimum-stability settings in your composer.json to influence this behavior.

  4. Tagging and Releasing: Ensure that your package versions are correctly tagged and released. If there are incorrect versions, consider deprecating them rather than deleting, as deleting can cause issues for users who might be relying on those versions.

  5. Testing with Different Configurations: Use a CI/CD pipeline to test your package against different combinations of PHP and Laravel versions to ensure compatibility.

Here's an example of how you might structure your composer.json for one of the versions:

{
  "require": {
    "php": "^8.0|^8.1|^8.2",
    "laravel/framework": "^8.0|^9.0"
  },
  "require-dev": {
    "orchestra/testbench": "^6.0|^7.0",
    "phpunit/phpunit": "^9.5"
  },
  "conflict": {
    "laravel/framework": ">=10.0"
  }
}

In this example, the conflict section is used to prevent this package version from being installed with Laravel 10 or higher.

  1. Debugging with Composer: Use Composer's verbose mode (composer update -vvv) to get more insight into how it resolves dependencies. This can help you identify why a particular version is being selected.

By carefully managing your version constraints and using Composer's features to control version resolution, you should be able to achieve the desired behavior for your package across different Laravel and PHP versions.

pixelpeter's avatar
pixelpeter
OP
Best Answer
Level 19

So it was really a combination of the two issues mentioned above:

1. An (unused) dependency broke the resolution in some combinations of php & laravel versions

   - carbon-cli/carbon-cli[1.2.0, ..., 1.2.1] require nesbot/carbon ^2.20 -> found nesbot/carbon[2.20.0, ..., 2.72.5] but the package is fixed to 3.8.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

2. Faulty older versions returned false resolutions which lead to the mismatched version

I removed the invalid versions from packagist (and github) and then it worked for all combinations of php & laravel

Please or to participate in this conversation.