Composer in Laravel: 9 Useful Features

Composer is a well-known tool to manage PHP project dependencies. But I'm pretty sure you're not using all of its features! In this tutorial, we'll show many less-known capabilities of Composer.


1. Versioning Syntax Options

Do you know the difference between the 1.3.*, ^1.3, and ~1.3 versions?

Composer uses quite a complex versioning system with a variety of operators. Let's look at the most common syntax options:

{
"vendor/package": "1.3.2", // exactly 1.3.2
"vendor/package": ">=1.3.2", // anything above or equal to 1.3.2
"vendor/package": "<1.3.2", // anything below 1.3.2
"vendor/package": "1.3.*", // >=1.3.0 <1.4.0
"vendor/package": "1.*", // >=1.0.0 <2.0.0
"vendor/package": "~1.3.2", // >=1.3.2 <1.4.0
"vendor/package": "~1.3", // >=1.3.0 <2.0.0
"vendor/package": "^1.3.2", // >=1.3.2 <2.0.0
"vendor/package": "^0.3.2", // >=0.3.2 <0.4.0
"vendor/package": "^1.1.0", // >=1.1.0 <2.0.0
}

There are more combinations supported by Composer, but you will mostly encounter these.


2. Check Outdated Packages

You might want to double-check which packages have newer versions, without actually running composer update. Run this:

composer outdated

And it will give you a list of packages with newer versions:

In this list, you can see all the direct packages that have newer versions available. Some of them will automatically update with the composer update command, but some of them might require manual version change.


3. Bumping Versions

Last year Composer introduced a new command composer bump. Its main job is...

The full tutorial [7 mins, 1251 words] is only for Premium Members

Login Or Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1057 lessons, total 42 h 44 min)
  • 79 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials