spatie/laravel-package-tools
A base PackageServiceProvider for Laravel package authors. Quickly register and publish config, views, translations, assets, routes, migrations, commands, view components/composers, and install commands—all via a clean, fluent API.
src/, config/, resources/) and lifecycle hooks, aligning with Laravel’s ecosystem. This reduces cognitive load for developers familiar with Laravel conventions.PackageServiceProvider abstracts registration logic (config, migrations, routes, etc.), enabling clean separation between package internals and host application code.configurePackage() and lifecycle hooks (e.g., booted(), register()), allowing TPMs to adapt the package to niche use cases without forking.vendor:publish) ensures seamless adoption.hasInstallCommand).package-skeleton-laravel repo, providing a pre-configured starter template.discoversMigrations()) could lead to unintended side effects if migrations are poorly named or depend on host-app schema.vendor:publish tags might clutter the host app’s publishable assets, requiring disciplined tag naming (e.g., {package-name}-{resource-type}).src/, resources/dist/) conflict with the team’s preferred architecture?configurePackage() offers?vendor:publish or package bootstrapping?PackageServiceProvider)?booted())?app/Packages/ instead of src/).src/, config/, resources/).package-skeleton-laravel as a template for new packages.hasConfigFile() and hasMigrations()).ServiceProvider::register() calls) with PackageServiceProvider.composer.json to include the package and its dependencies.configurePackage() in the existing service provider.vendor:publish --tag={package}-config).booted() for post-registration logic).spatie/laravel-package-tools has minimal PHP requirements).vendor:publish tags or service provider names.spatie/laravel-package-tools via Composer.PackageServiceProvider in the package’s main provider.configurePackage().resources/stubs/{Provider}.php.stub) for service providers.InstallCommand to automate vendor:publish for end users.{package}-assets) for clarity.PackageServiceProvider API updates).composer.json constraints to pin major versions (e.g., ^2.0).spatie/laravel-package-tools may pull in spatie/laravel-permission).composer why-not to audit dependency conflicts.booted() or register() to minimize merge conflicts during updates.configurePackage() for troubleshooting (e.g., Log::debug('Package configured:', $package->toArray())).vendor:publish tags and their purposes (e.g., {package}-migrations vs. {package}-config).README example for end users (e.g., "Run php artisan vendor:publish --tag={package}-assets to install CSS").vendor:publish tags to avoid collisions (e.g., acme-auth-config vs. acme-billing-config).public/vendor/{package-name}/).discoversMigrations() in large packages; explicitly list migrations to reduce discovery overhead.hasAssets() registration.runsMigrations() judiciously to avoid race conditions.| Failure Scenario | Impact | Mitigation |
|---|---|---|
Missing configurePackage() |
Package fails to register resources. | Enforce CI checks for configurePackage() presence. |
Duplicate vendor:publish tags |
Overwrites host app files. | Use unique, descriptive tags (e.g., {package}-{resource}). |
| Migration conflicts | Database errors on php artisan migrate. |
Test migrations in isolation; use runsMigrations() only for critical packages. |
Broken InstallCommand |
End users can’t publish resources. | Validate command logic with unit tests. |
| Laravel version mismatch | Package fails to load. | Pin Laravel version in composer.json (e.g., ^10.0). |
| Asset publishing failures | CSS/JS |
How can I help you explore Laravel packages today?