name: package-service-provider description: "Use this skill when changing a Laravel package service provider: config merges, routes, views, translations, publishing, migrations, assets, Blade components, commands, console-only behavior, or package metadata." license: MIT metadata: author: laravel
Package Service Provider
Primary Goal
Wire package capabilities through explicit Laravel service provider code without defaulting to spatie/laravel-package-tools.
Workflow
- Inspect the package service provider and keep its existing method split. If the package uses names like
registerResources,registerPublishing,registerBladeComponents,registerConsole, orregisterAboutMetadata, add new behavior to the matching concern. - Put container bindings and
mergeConfigFromcalls inregister()when the host app must be able to override configuration. - Put resource loading in boot-time methods with Laravel-native APIs such as
loadRoutesFrom,loadViewsFrom, andloadTranslationsFrom. - Guard console-only publishing and command registration with
runningInConsole()before callingpublishes,publishesMigrations, orcommands. - Add tests for the observable package behavior: merged config, loaded routes, publish tags, command registration, or about metadata.
References
src/*ServiceProvider.phpconfig/*.phproutes/*.phpresources/views/lang/database/migrations/src/Console/Commands/
Examples
- Wire a new publish tag by adding a
publishesmap inside the existing console-guarded publishing method and naming the tag withexpressive-*. - Add a command by creating the command class, importing it in the provider, and adding it to the
commandsarray inside therunningInConsole()guard.
Anti-Patterns
- Loading host app state too early during provider registration.
- Calling
env()outside config files; avoidenv() outside configby using config values aftermergeConfigFrominstead. - Registering web-only concerns unconditionally when the package can run in console contexts.
- Replacing explicit provider methods with
spatie/laravel-package-toolsby default.