spatie/laravel-package-tools
Laravel package helper from Spatie providing a base PackageServiceProvider to quickly register and publish config, migrations, routes, views, translations, assets, commands, install scripts, view components/composers, and shared view data with minimal boilerplate.
PackageServiceProvider extends Laravel’s core patterns (e.g., ServiceProvider, Package DSL) without introducing breaking changes. This ensures compatibility with Laravel’s lifecycle (booting, registering, etc.).src/, resources/, database/migrations/) but allows customization via methods like discoversMigrations(path: string). This balances consistency with adaptability.PackageServiceProvider, define configurePackage). No additional infrastructure (e.g., Composer scripts, custom CLI tools) is needed.hasCommand() registers commands via Artisan::register()).vendor:publish tag system (e.g., --tag=package-name-assets).ServiceProvider, Artisan) remain stable. Risk: Breaking changes in Laravel (e.g., new service provider booting order) could require updates to the package.
src/Components/ for Blade components). Risk: Teams with existing packages may need to refactor.
path: overrides (e.g., hasViewComponents('custom/path')) or the package-skeleton as a template.orchestra/testbench or pestphp for package testing.hasViewComponents()) add slight reflection overhead. Risk: Negligible for most use cases.composer.json constraints.)vendor:publish tags dynamically)?config/)?| Current State | Migration to laravel-package-tools |
Effort |
|---|---|---|
| No package structure | Adopt the package-skeleton and refactor. | High (1–3 days) |
Custom ServiceProvider |
Extend PackageServiceProvider and migrate features (e.g., hasConfigFile() instead of manual publishing). |
Medium (1 day) |
Manual vendor:publish tags |
Replace with hasAssets(), hasConfigFile(), etc. |
Low (few hours) |
| External CLI tools | Replace with hasCommand() and InstallCommand. |
Medium (1 day) |
| Non-standard directory layout | Use path: overrides or restructure to match conventions. |
Medium (1–2 days) |
laravel-permission).orchestra/package-tools (but this is Laravel-specific).composer.json:
"require": {
"spatie/laravel-package-tools": "^2.0"
}
PackageServiceProvider in your main provider.Config::publish()) with DSL methods (e.g., hasConfigFile()).src/Components/ for Blade).vendor:publish tags and Artisan commands work as expected.README.md to reflect new installation commands (e.g., php artisan vendor:publish --tag=...).publishes() in ServiceProvider).configurePackage(), making it easier to audit.laravel-package-tools updated with Laravel versions.Log::info() in InstallCommand).--force flag or custom tags.runsMigrations() is called if auto-loading is desired.How can I help you explore Laravel packages today?