Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove a package from Laravel using PHP Composer?

What is the correct way to remove a package from Laravel using PHP Composer?

So far I've tried:

  1. Remove declaration from file composer.json (in the "require" section)
  2. Remove any class aliases from file app.php
  3. Remove any references to the package from my code :-)
  4. Run composer update
  5. Run composer dump-autoload

None of these options are working! What am I missing?

like image 211
igaster Avatar asked Apr 17 '14 06:04

igaster


People also ask

How do I delete a Laravel project?

Just delete the folder. Composer just facilitate to create a laravel project on your behalf with correct version and dependencies. Show activity on this post. Yes it is a just a delete command.

Where are the packages pulled from composer stored in Laravel?

And the package can be found in the project's vendor/ directory.


2 Answers

Composer 1.x and 2.x

Running the following command will remove the package from vendor (or wherever you install packages), composer.json and composer.lock. Change vendor/package appropriately.

composer remove vendor/package 

Obviously you'll need to remove references to that package within your app.

I'm currently running the following version of Composer:

Composer version 1.0-dev (7b13507dd4d3b93578af7d83fbf8be0ca686f4b5) 2014-12-11 21:52:29 

Documentation

https://getcomposer.org/doc/03-cli.md#remove

Updates

  • 26/10/2020 - Updated answer to assert command works for v1.x and v2.x of Composer
like image 121
steadweb Avatar answered Sep 28 '22 02:09

steadweb


I got it working... The steps to remove a package from Laravel are:

  1. Remove the declaration from file composer.json (in the "require" section)
  2. **Remove Service Provider from file config/app.php (reference in the "providers" array)
  3. Remove any class aliases from file 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 the vendor folder and will rebuild the Composer autoloading map.
  6. Manually delete the published files (read the comment by zwacky)

It will remove the package folder from the Vendor folder.

like image 36
igaster Avatar answered Sep 28 '22 02:09

igaster