Remove Composer Package From Laravel

Composer is an application-level package manager for the PHP programming language that provides a standard format for managing dependencies of PHP software and required libraries.

As a PHP developer you will need to add or remove some functionality on daily basics. These Composer packages can be anything that saves you time and provides you proper functionality. Packages like Carbon can help you with dates or Spatie media library can help you with managing media into you application or Debugbar can handle debugging purpose.

But sometimes you add package for your function requirement but later on you need to remove those functionality. For example you need to create sitemap for you application. so you use spatie/laravel-sitemap package to create sitemap. But later on, you wish to use some third party sitemap generator. So you need to remove this package.

Adding a package to Laravel

First of we need to add package to our Laravel application. We will remove this package in next step.

As per example, We are going to use Laravel Sitemap package which is really handy to create sitemap programmatically for large sites. To install this package enter below command into terminal :

composer require spatie/laravel-sitemap

It will take some time to download/install package. But when it completes, It will automatically add below line into your composer.json file.

"spatie/laravel-sitemap": "^5.8"

It will also add other files to vendor/spatie/laravel-sitemap directory. Those files are core files for package.

Remove or Uninstall Composer Package

With below command we have installed sitemap generator package to our application now we can remove it using below command :

composer remove spatie/laravel-sitemap

This will revert changes to compsoer.json file and as well as remove directory from vendor folder.

Now your package is removed from application. Don't forget that you have to edit your code and ensure that the package is not being used.

Generally, you need to remove package from config/app.php file as providers and aliases. If you can those methods statically then you need to check it in related functionality of your code.

Share your thoughts

Ask anything about this examples