How to Remove a Package from Laravel using Composer

Here is the step-by-step guide to remove a package from Laravel using Composer.

  1. Remove the package declaration from the composer.json file (in the “require” section).
  2. Use the “composer remove” command.
  3. Remove Service Provider from app/config/app.php file.
  4. Remove any Class Aliases from the app/config/app.php file.
  5. Run migrations (if necessary).
  6. Clear cached configurations.
  7. Check for remaining references.

Let’s go through step-by-step.

Step 1: Remove the package declaration from the composer.json file

Open the composer.json file located at the root of your Laravel project.

Locate the require section and find the package you want to remove.

Remove the line that references the package.

Step 2: Use the composer remove command

Go to your Laravel root and use this command:

composer remove vendor/package-name

Replace the vendor/package-name with the actual name of the package you want to remove.

Step 3: Remove the Service Provider from the app/config/app.php file

Open the config/app.php file.

Locate the providers array.

Delete the service provider related to the package.

Step 4: Remove any Class Aliases from the app/config/app.php file

Still, in the config/app.php file, locate the aliases array.

Delete any aliases related to the package.

Step 5: Run migrations (if necessary)

If the package added database tables or made other changes to your database, you might need to reverse these changes.

This can often be done by running:

php artisan migrate:rollback

Step 6: Clear cached configurations

It’s important to clear these caches to ensure the application doesn’t reference the removed package:

php artisan config:clear

Step 7: Check for remaining references

You must review your codebase for any lingering references to the removed package. This could be in controllers, views, middleware, routes, or other configuration files. Remove or adjust these references as necessary.

That’s it!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.