How to properly install Laravel expansion pack using Composer

Source: Internet
Author: User
Tags composer install

Problem description

We often add expansion packs to existing projects, sometimes because of incorrect documentation, such as from this document:

Composer Update This command may cause significant damage to the project in our current logic.

Because the logic of composer update is to update all expansion packs to the latest version with the extension package version rules specified by Composer.json, note that all expansion packs, for example, you used monolog at the beginning of the project, when the configuration information was

"Monolog/monolog": "1.*",

The installation is Monolog 1.1 version, and one months later now, Monolog is already 1.2, after running the command directly updated to 1.2, then the project did not test for 1.2, the project suddenly become very unstable, the situation sometimes worse than this, Especially in a huge project where you don't write a full coverage test for a project, something is broken and you don't know.

Which command should we use? Install, update or require?

Next we explain.

Simple explanation

    • Composer Install-If there is a Composer.lock file installed directly, otherwise from Composer.json install the latest expansion pack and dependencies;
    • Composer Update-Installs the latest expansion packs and dependencies from Composer.json;
    • Composer Update Vendor/package-from the Composer.json or the corresponding package configuration, and update to the latest;
    • Composer require New/package-add installation New/package, you can specify a version, such as: Composer require new/package ~2.5.

Process

Next, we will introduce several daily production processes to facilitate the understanding.

Process one: New project flow

    1. Create Composer.json and add dependencies to the extension package;
      • Running composer install, installing the expansion pack and generating composer.lock;
      • Commit Composer.lock to the code version controller, such as: git;

Process two: Project collaborators install existing projects

    • After the project is cloned, run composer install directly from the root directory, installing the specified version of the extension package from the Composer.lock and its dependencies;

This process applies to deployment of production environment code.

Process three: Add a new expansion pack for a project

    • Add an expansion pack using composer require vendor/package;
    • Commit the updated Composer.json and Composer.lock to the code version controller, such as: git;

About the Composer.lock file

The Composer.lock file holds the version records that are dependent on each code (see), commits to the version controller, and is used with the composer install to ensure consistency of the code versions that are running in the team's developer environment and the online production environment.

About installation methods for expansion packs

So, ready to add an extension package, install, update, require three commands can be used to install the expansion package, choose which is the right one?

The answer is: Use the composer require command

Also, after you manually modify the Composer.json Add expansion pack, the composer update new/package the way to specify an expansion pack update, and it can be installed correctly, but this method is not recommended, because once you forget to finalize the extension package name, Will enter the state of perdition, do not give yourself to leave a hole.

The above concepts are confusing to both novice and veteran, primarily remembering this concept:

New additions to the original project are installed using composer require new/package this way.

Finish.

Welcome to Laraveltips, a public number focused on Laravel developers, dedicated to helping developers better grasp the Laravel framework and improve their development efficiency.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.