How do I install and use a Laravel package?
Laravel packages allow you to extend application functionality efficiently. From authentication and admin panels to search tools, AI integrations, and more, packages save development time and reduce complexity.
1. Install via Composer
Use Composer, Laravel’s dependency manager, to install a package:
composer require vendor/package-namePro-tip: You can specify a version constraint to ensure compatibility:
composer require vendor/package-name:^1.0.4If the package is for development tools only (like Debugbar or Pest), use:
composer require vendor/package-name --devNote: Running composer require automatically updates composer.json and composer.lock.
2. Service Provider Registration / Auto-Discovery
Modern Laravel packages support auto-discovery, so most of the time you don’t need manual registration. If a package requires manual registration:
// Add this provider to bootstrap/providers.php array in Laravel 11/12
Vendor\Package\ServiceProvider::class,This replaces the older practice of manually editing config/app.php in Laravel 5.x.
3. Publish Configuration & Assets
Many packages include configuration files, migrations, or assets. Publish only what you need:
# Publish config files (streamlined for Laravel v11/v12)
php artisan config:publish vendor/package-name
# Or use vendor:publish with tags
php artisan vendor:publish --tag=package-name-config
php artisan vendor:publish --tag=package-name-migrationsPro-tip: Using --tag prevents unnecessary clutter in your project.
4. Run Migrations (if applicable)
If the package adds database tables, run:
php artisan migrate5. Implementing the Package
Integrate the package functionality using Dependency Injection or Facades for maintainable and testable code.
Dependency Injection Example
use Vendor\Package\SomeClass;
public function index(SomeClass $package) {
$package->performAction();
}Facade Example
use Vendor\Package\Facades\PackageName;
public function store() {
PackageName::doSomething();
}6. Updating & Removing Packages
- Update all packages:
composer update - Remove a package:
composer remove vendor/package-name
7. Documentation & Research
- Always read the package’s official documentation for advanced usage, options, and compatibility.
- Choose packages with active community support to ensure reliability.
8. Pro-Tips for Laravel 11/12
- Use version constraints to prevent breaking changes.
- Leverage auto-discovery to simplify service provider management.
- Publish only necessary configuration or migrations using tags.
- Implement functionality with Dependency Injection wherever possible for easier testing.
- Engage with the package community for updates, bug fixes, and improvements.
Summary
- Install packages via Composer (
--devfor dev tools) - Auto-discovery handles most service providers; manual registration in
bootstrap/providers.phpif required - Publish only required files with
--tagorconfig:publish - Run migrations when needed
- Integrate using Dependency Injection or Facades
- Keep packages updated and monitor version compatibility
- Read documentation and engage with the package community
By following these modern Laravel 11/12 practices, you can efficiently leverage packages while keeping your application maintainable, testable, and up-to-date.
Related Answers
Still need help?
Talk to our Laravel experts
We've handled GDPR/CCPA compliance for dozens of EU & US Laravel.
