Search code examples
phplaravellaravel-5composer-phpshopping-cart

LaravelShoppingcart not work in laravel5.6


when i want to install LaravelShoppingcart , with composer :

$ composer require gloudemans/shoppingcart

This return errors.Because composer update laravel version 5.5 to 5.6 and ShoppingCart not work 5.6 yet.How can i install this package with dont update composer ?


Solution

  • You either need to use Laravel 5.5 or fork the package and bump the version dependencies yourself:

    // composer.json, 5.5 is the highest supported version
    "require": {
        "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
        "illuminate/session": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*",
        "illuminate/events": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*"
    },
    

    There is a passing pull request in place though:

    https://github.com/Crinsane/LaravelShoppingcart/pull/425

    However, if you can't wait for the pull request to be accepted, the change is trivial.

    Fork the package

    1. Update composer.json:

      "require": {
           "illuminate/support": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*",
           "illuminate/session": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*",
           "illuminate/events": "5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*"
       },
       "require-dev": {
           "phpunit/phpunit": "~5.0|~6.0|~7.0",
           "mockery/mockery": "~0.9.0",
           "orchestra/testbench": "~3.1"
       },
      
    2. Commit the changes.

    3. Create a release of your new fork.

    Create a release in GitHub

    1. Go to the page for new fork and click releases

    Click Releases

    1. Click Draft New Release

    enter image description here

    1. Give the release a new version (2.4.6 would be used in the example below)

    enter image description here

    1. Click Publish

    You now have a released version in your personal GitHub account which you can instruct composer to use for installation.

    Install the fork using composer

    In the repositories section of your composer.json add your public GitHub repository:

    // "repositories" may not exist in your composer.json file.
    // add it as a sibling to "require"
    "repositories": [
      {
        "type": "git",
        "url": "https://github.com/username/forked-repository"
      }
    ],
    

    and add an entry to the require section:

    // change the version - 2.4.6 - to match your fork's version
    "require": {
      "username/forked-repository": "2.4.6"
    }
    

    You can now run:

    composer update
    

    and the fork will be installed in your application.