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:
Example:
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:
✅ Step 4: Check Autoloading
After removal, regenerate the Composer autoloader to ensure everything is cleaned up:
๐งผ Step 5: Optional Cleanup (Manual)
If you want to be extra clean:
-
Check
app/Providers
,app/Http/Middleware
, androutes/
for leftover code. -
Delete any custom blade files, assets, or database entries related to the package.
๐ Summary
Task | Command / Action |
---|---|
Remove package | composer remove vendor/package-name |
Clear Laravel cache | php artisan config:clear , etc. |
Regenerate autoload | composer dump-autoload |
Manual code/config cleanup | Remove from providers, config, routes, views |