How to Remove a Package from Laravel using PHP Composer?

How to Remove a Package from Laravel using PHP Composer?
How to remove a package from Laravel using PHP Composer?

Today we'll look at how to uninstall a package from Laravel using PHP Composer. Laravel, a popular PHP framework, offers developers a simple approach to managing dependencies via Composer.

What is a composer?

Composer is a PHP dependency management tool. It lets you declare the libraries on which your project depends and maintains them (installs and updates) for you. Laravel manages its dependencies using Composer. So, every time you install a Laravel package, you are utilizing Composer.

Composer handles version limitations, autoloading, and dependency resolution to make package installation and administration easier. However, you may need to delete a package from your Laravel project at some point.

Remove a package from Laravel using PHP Composer.

Running the following command will uninstall the package from vendor (or wherever you set up packages), composer.json, and composer.lock. Change vendor/package properly. Please clear the cache before uninstalling a package from a composer.json declaration:

php artisan cache:clear
php artisan config:clear

If you refuse to remove the cache and then get a "class not found" error, please reinstall the package, clear the cache, and then remove it again.

The procedures for uninstalling a package from Laravel.

  1. Remove the declaration in the "require" section of composer.json.
  2. Remove Service Provider from the file config/app.php (referenced in the "providers" array).
  3. Remove any class aliases from the config/app.php file.
  4. Remove any package references from your code.
  5. Run composer update vendor/package-name. This will delete the package folder from the vendor folder and recreate the composer autoloading map. e.g., "Composer remove dompdf/dompdf
composer update vendor/package-name
composer update
  1. Manually delete the published files.

It will delete the package folder from the vendor folder.

Read more