How to remove a package from Laravel using compose

2019-01-07 02:06发布

What is the right way to remove a package from Laravel 4? So long I've tried:

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

Not working! Am I missing something?

Some packages publish their configuration via "artisan config:publish ...". Is there a way to "unpublish" them?

9条回答
老娘就宠你
2楼-- · 2019-01-07 02:18

Before removing a package from composer.json declaration, please remove cache

php artisan cache:clear  
php artisan config:clear 

If you forget to remove cache and you get class not found error then please reinstall the package and clear cache and remove again.

查看更多
来,给爷笑一个
3楼-- · 2019-01-07 02:19

Running the following command

    composer remove Vendor/Package Name  

Thats all.No need composer update. Vendor/Package Name is just directory as installed before

查看更多
beautiful°
4楼-- · 2019-01-07 02:19

Normally composer remove used like this is enough:

$ composer remove vendor/package

but if composer package is removed and config cache is not cleaned you cannot clean it, when you try like so

php artisan config:clear

you can get an error In ProviderRepository.php line 208:

Class 'Laracasts\Flash\FlashServiceProvider' not found

this is a dead end, unless you go deleting files

$rm bootstrap/cache/config.php

And this is Laravel 5.6 I'm talking about, not some kind of very old stuff.

It happens usually on automated deployment, when you copy files of a new release on top of old cache. Even if you cleared cache before copying. You end up with old cache and a new composer.json.

查看更多
家丑人穷心不美
5楼-- · 2019-01-07 02:23

Got it working... 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 (read comment by zwacky)

It will remove the package folder from "Vendor" folder

查看更多
Evening l夕情丶
6楼-- · 2019-01-07 02:23

you can remove any package just by typing follwing command in terminal, and just remove the providers and alias you provided at the time of installing the package, if any and update the composer,

composer remove vendor/your_package_name
composer update
查看更多
Animai°情兽
7楼-- · 2019-01-07 02:23

If you are still getting the error after you have done with all above steps, go to your projects bootstrap->cache->config.php remove the provider & aliases entries from the cached array manually.

查看更多
登录 后发表回答