How to Remove Package from Laravel (Composer)

How to Remove Package from Laravel (Composer)

How to Remove a Package from Laravel (Composer)

When you no longer need a package in your Laravel application, it’s important to remove it properly to avoid unnecessary bloat or conflicts.

✅ Step 1: Remove the Package via Composer

Run the following command in your terminal from your Laravel project root:

composer remove vendor/package-name

Example:

composer remove spatie/laravel-permission

This command will:

  • Remove the package from the vendor/ directory.

  • Delete the entry from composer.json automatically.

  • Update the composer.lock file.

✅ Step 2: Remove Configuration or Usage (Optional but Recommended)

If the package was being used, make sure to:

  • Remove related code in your service providers, middlewares, or anywhere else you integrated it.

  • Delete any config files generated (e.g., config/permission.php).

  • Clean up routes, views, or migrations added by the package.

✅ Step 3: Clear Configuration & Cache

Sometimes, Laravel caches parts of the application, so it’s good to clear them:

php artisan config:clear php artisan cache:clear php artisan route:clear php artisan view:clear

✅ Step 4: Check Autoloading

After removal, regenerate the Composer autoloader to ensure everything is cleaned up:

composer dump-autoload

๐Ÿงผ Step 5: Optional Cleanup (Manual)

If you want to be extra clean:

  • Check app/Providers, app/Http/Middleware, and routes/ for leftover code.

  • Delete any custom blade files, assets, or database entries related to the package.

๐Ÿ“ Summary

TaskCommand / Action
Remove packagecomposer remove vendor/package-name
Clear Laravel cachephp artisan config:clear, etc.
Regenerate autoloadcomposer dump-autoload
Manual code/config cleanupRemove from providers, config, routes, views
Soeng Souy

Soeng Souy

Website that learns and reads, PHP, Framework Laravel, How to and download Admin template sample source code free.

Post a Comment

CAN FEEDBACK
close