How to properly install Laravel expansion pack using Composer

Source: Internet
Author: User
Tags composer install

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

composer updateThis command, in our present logic, can cause great damage to the project.

Because composer update the logic is to update all expansion packs to the latest version according to the extension package version rules specified by Composer.json, note 所有扩展包 that, for example, you used monolog at the beginning of the project, The configuration information at that time 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 simple explanation
    • composer install-If you have composer.lock files, install them directly, otherwise install the latest expansion pack and dependencies from Composer.json;

    • composer update-Install 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 the 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;

    • Run composer install , install the expansion pack and composer.lock generate it;

    • Commit composer.lock to the code version controller, such as: git;

Process two: Project collaborators install existing projects
    • After cloning the project, the root directory runs composer install directly composer.lock from the installed 指定版本 expansion pack and its dependencies;

This process applies to deployment of production environment code.
Process three: Add a new expansion pack for a project
    • Use composer require vendor/package Add expansion packs;

    • Commit the updated composer.json and composer.lock to the code version controller, such as: git;

About the Composer.lock file

composer.lockThe file maintains a version record (see) that is dependent on each code, commits to the version controller, and works composer install together 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: composer require Use the command

In addition, after you manually modify the Composer.json add expansion composer update new/package Pack, the way to specify the extension package updates, you can also install the correct, 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:

composer require new/package this way to install.

Finish.

How to properly install Laravel expansion pack using Composer

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.