Laravel does not come with pre-installed packages. You will need to install them manually before you can make use of them in your project.
Installing these packages using composer is simple if you know the exact package names or their GitHub repositories.
In this tutorial, I show how you can add remove package using composer in Laravel.
Contents
1. Add package using composer
For example purpose, I am installing the Yajra Datatables package –
composer require yajra/laravel-datatables-oracle:"^10.0"
After installation, in composer.json
file a new line was added under the require
–
"require": { "php": "^8.0.2", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.19", "laravel/sanctum": "^3.0", "laravel/tinker": "^2.7", "yajra/laravel-datatables-oracle": "^10.0" },
2. Remove package using composer
To remove the above-installed package execute the following command –
composer remove yajra/laravel-datatables-oracle
Package name is removed from composer.json
file –
"require": { "php": "^8.0.2", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.19", "laravel/sanctum": "^3.0", "laravel/tinker": "^2.7" },
Make sure to also remove any reference stored in the project. For example, when setting up Yajra Datatables also need to update config/app.php
file and to use this need to import and call them.
In this case, need to remove the Yajra from ‘providers’ and ‘alias’ in the config/app.php
file. Also, need to remove the code from the pages if used.
3. Conclusion
If a package is no longer needed then it is better to remove them from the project. In case you mistakenly removed the package then you can reinstall it following the above method.
If you found this tutorial helpful then don't forget to share.