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 basis. These Composer packages can be anything that saves you time and provides you with proper functionality. Packages like Carbon can help you with dates or Spatie media library can help you with managing media in you application or Debugbar can handle debugging purposes.
But sometimes you add a package for your function requirement but later on, you need to remove those functionalities. For example, you need to create a sitemap for your application. so you use spatie/laravel-sitemap package to create a 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 a package to our Laravel application. We will remove this package in the next step.
As per example, We are going to use the Laravel Sitemap package which is handy to create a sitemap programmatically for large sites. To install this package enter the below command into the 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 to your composer.json file.
Remove or Uninstall Composer Package
With below command we have installed sitemap generator package to our application now we can remove it using the below command :
composer remove spatie/laravel-sitemap
This will revert changes to compsoer.json file and as well as remove a directory from vendor folder.
Now your package is removed from the 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 a package from config/app.php file as providers and aliases. If you can those methods statically then you need to check it in the related functionality of your code.