Getting Started with Composer for Laravel Development
When you are developing a project in Laravel, you will need to install and know how to use the composer to manage your third-party dependencies.

When you are developing a project in Laravel, you will need to install and know how to use the composer to manage your third-party dependencies.
Dependencies are essential for any kind of modern web development. You may need some sort of functionalities for your web application can easily be included into your project using third party libraries.
There are many third-party libraries which we can use to make our life easy by simply adding them to our project. Composer is a dependency manager for PHP libraries. You can find a vast selection of compatible libraries or packages on Packagist website.
Most popular frameworks like Laravel can be found on Packagist, as Laravel itself is a collection of different packages.
This post will be a dead simple guide to get you started with using Composer and manage dependencies for Laravel.
Installing Composer
First thing first, you have to install Composer, before anything else. Follow below steps to install Composer on your computer.Installing on Mac
If you are using a Mac, then we recommend you to install Composer using Homebrew. Homebrew is an open source software package manager for Mac. If you need to install the Homebrew use below command to install it first./usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"Once you have installed the Homebrew on your machine, you can install the composer using below command.
brew install composerInstalling on Windows
To install on windows, you can download the windows executables from Composer Download page and follow the simple installation process.Once you have installed the composer on your machine, simply type composer and hit enter. You will be presented with a list of all composer commands.
Creating a new project using Composer
As we mentioned above, the composer is a dependencies management for PHP. You can declare all your dependencies in a single file calledcomposer.json by adding system requirements and requiring the packages.
You can create a new Laravel project using composer create-project command. Firstly you need to clone a project from an existing package or framework using below command.
composer create-project package-name destination-folder version- package name: e.g. laravel/laravel
- desctination folder: e.g. app, any folder or project name
- version: e.g. 5.7.* (optional)
composer create-project laravel/laravel blogIn most cases, you clone a project from a Github or Bitbucket repository. After cloning you can install all predefined dependencies using below command.
composer installUsing Composer during Laravel Development
During the development of your project, you might want to install extra packages to add extra functionality to your project.You can install a new package by running below command.
composer require package-name:versionFor example,
composer require intervention/imageAbove command will add intervention/image package to your project.
If you want to update all packages to the latest version, you can run below command.
composer updateIf you want to remove a package, you can run below command.
composer remove package-nameUsing Composer during the Deployment
Once you have your application ready for deployment, you need to install all dependencies on your server. Composer keeps records of all packages required for your application in a separate file calledcomposer.lock
Once you have pushed your project codebase to the server, then you can run composer install command to install all dependencies. This command will install all dependencies listed in composer.lock file.