- Laravel 5.x Cookbook
- Alfred Nutile
- 385字
- 2021-07-14 09:56:49
Working with Composer install command and avoiding Composer update
Composer is an amazing tool in PHP which allows us to pull in libraries from cover how to install a library and note some steps to save time.
Getting ready
We covered installing Composer on your Mac in Chapter 1, Setting Up and Installing Laravel, though you can use it inside Homestead if you need to.
How to do it...
Perform the following steps to install Guzzle using Composer:
- In this example, we will use Composer to install Guzzle (a powerful PHP HTTP client). Make sure you are in your
App
directory, and in this example, I will be on my local computer and not in Homestead just to make the file processing go faster:>composer require "guzzlehttp/guzzle":"^6.1"
This will take a minute or less to run.
- And that is it!
How it works...
First, let me say this is a good example of a short tip, which is better than a long one. Maybe other instructions will tell you to put this into your composer.json
file and then run composer update
, but stay away from composer update
unless you really like waiting around, and you really need to update everything you have installed!
What else happened here is really good to understand, since this is a big part of Laravel and modern PHP. Composer added the library to your vendor
folder:

It made a folder for the libraries called Vendor Name
and Projects Name
. Then, it updated composer.json
to load this new library!

This means we did not even have to edit the file.
Also note that there is a composer.lock
file now in the root of your application, which you never edited. It shows what Composer pulled in to satisfy the dependencies of all the libraries that you have installed, as well as the file called vendor/autoload.php
to build up all the PHP namespaces.
We will use Composer a number of times in this book. It really has changed the way we build apps in PHP for the better.
There's more...
If we look inside the Composer.json
file, we will also notice some default namespaces and hooks that we can add to as needed:

See also
- Composer Docs: https://getcomposer.org/doc/
- Guzzle (a great way to do API requests and other HTTP requests in PHP): https://packagist.org/packages/guzzlehttp/guzzle
- Practical Data Analysis Cookbook
- Spring Boot+Spring Cloud+Vue+Element項目實戰:手把手教你開發權限管理系統
- JavaScript+jQuery開發實戰
- Learning Bayesian Models with R
- C#程序設計教程
- Python數據分析(第2版)
- KnockoutJS Starter
- SQL Server 2008中文版項目教程(第3版)
- 百萬在線:大型游戲服務端開發
- Data Manipulation with R(Second Edition)
- Go Systems Programming
- C/C++程序設計教程
- JSP大學實用教程
- .NET應用架構設計:原則、模式與實踐
- Learning VMware vCloud Air