php

How to remove a package from Laravel using composer?

Problem

What is the right way to remove a package from Laravel ? Some packages publish their configuration via artisan config:publish … Is there a way to “unpublish” them?

Solution

The steps to remove a package from Laravel are:

  1. Remove declaration from composer.json (in “require” section)
  2. Remove Service Provider from app/config/app.php (reference in “providers” array)
  3. Remove any Class Aliases from app/config/app.php
  4. Remove any references to the package from your code
  5. Run composer update vendor/package-name. This will remove the package folder from vendor folder and will rebuild composer autoloading map.
  6. Manually delete the published files

It will remove the package folder from “Vendor” folder

Additional Advice

In addition, here are a few more suggestions in case you run into any unforeseen issues.

So even after you have followed all the steps from the above, sometimes it can be that files simply stuck in composer cache and it does not want to update. In that case, you need to clear your composer cache by running the following command in your terminal:

$ composer clearcache

It’s fine if you want to use clear-cache as well, which is an alias for clearcache.

If you ever receive a weird warning message, such as the below, that will be a clear sign that you are having issues with the cache.

"The requested package vendor/mypackage could not be found in any version,
there may be a typo in the package name"

After you are ready and have cleared your composer cache, try running

composer dump -o

since that will regenerate the lock file and make sure your minimum requirements are full-filled.

About the author

laravelrecipies