Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Package Tools

Laravel Package Tools Laravel Package

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.

View on GitHub
Deep Wiki
Context7

spatie/laravel-package-tools streamlines building Laravel packages by providing a robust PackageServiceProvider that registers common package resources with a clean, fluent API. Define your package’s name, assets, routes, migrations, and commands in one place while automatically handling publishing and integration with the host app.

Ideal for package authors who want consistent structure and less boilerplate, it also supports an interactive install command to guide users through setup steps.

  • Fluent configuration via PackageServiceProvider / Package
  • Register & publish config, views, translations, assets
  • Add routes, migrations, and artisan commands
  • Support view components, view composers, and shared view data
  • Optional guided setup with a customizable InstallCommand
Frequently asked questions about Laravel Package Tools
How does spatie/laravel-package-tools reduce boilerplate when building Laravel packages?
The package provides a `PackageServiceProvider` that replaces manual registration of config files, migrations, views, and other assets. Instead of writing repetitive code for `publishes()` or `mergeConfigFrom()`, you define resources declaratively in a single `configurePackage()` method. For example, `hasConfigFile()` and `hasMigrations()` handle all the underlying Laravel plumbing automatically.
Can I use this package with Laravel 10 or 11? What about older versions?
The package is designed for modern Laravel versions (10.x and 11.x) and requires PHP 8.1+. Check the [GitHub repository](https://github.com/spatie/laravel-package-tools) for version-specific branches or compatibility notes. Older Laravel versions (e.g., 8.x) may not be supported due to dependency changes, but you can verify by inspecting the `composer.json` constraints.
How do I add an interactive install command to my Laravel package?
Use the `hasInstallCommand()` method in your `configurePackage()` block. Pass a closure to configure the `InstallCommand`, where you can chain methods like `publishConfigFile()`, `publishMigrations()`, or `askToStarRepoOnGitHub()`. This generates an Artisan command (e.g., `php artisan your-package:install`) that guides users through setup interactively.
What’s the difference between `hasAssets()` and manually publishing files in `boot()`?
The `hasAssets()` method automatically publishes all files in your package’s `resources/assets` directory to the host app’s `public/` folder, using Laravel’s `vendor:publish` system. Manually publishing in `boot()` requires explicit paths and tags, which can be error-prone. `hasAssets()` also integrates with the `InstallCommand` for a seamless user experience.
Does this package support custom migration paths (e.g., migrations outside `database/`)?
By default, the package expects migrations in `database/migrations/`, but you can override this with `discoverMigrations()` in your `PackageServiceProvider`. For non-standard paths, use `hasMigration()` with a custom path string. However, deviating from Laravel conventions may require additional configuration or testing to ensure compatibility.
How do I test a Laravel package built with spatie/laravel-package-tools?
Test package functionality using Laravel’s testing tools (Pest or PHPUnit). Mock the `PackageServiceProvider` to verify registration logic, and test published assets by simulating `vendor:publish`. For migrations, use `Schema::hasTable()` assertions. The package itself includes unit tests for its core features, which you can reference as examples.
Will this package work for open-source Laravel packages? Are there versioning concerns?
Yes, it’s ideal for open-source packages. However, since it ties to Laravel versions, ensure your package’s `composer.json` specifies compatible Laravel ranges (e.g., `^10.0`). Use semantic versioning for your package to match Laravel’s updates. For example, if your package requires Laravel 11, document this clearly to avoid user conflicts.
Can I customize the directory structure (e.g., move migrations to `app/`)?
The package enforces a standard structure (`src/`, `resources/`) for consistency, but you can override paths in `configurePackage()`. For example, use `hasMigration('custom/path/to/migration.php')` or `discoverMigrations('app/Migrations')`. However, this may complicate maintenance and could confuse users expecting Laravel’s default layout.
What if my package needs to register view composers or shared data?
Use `hasViewComposer()` to register composers (e.g., `hasViewComposer('*', MyComposer::class)`) and `sharesDataWithAllViews()` to pass shared data to views. These methods integrate with Laravel’s view system and are automatically handled during package registration. No manual `View::composer()` or `View::share()` calls are needed.
Are there alternatives to spatie/laravel-package-tools for Laravel package development?
Alternatives include rolling your own `ServiceProvider` with manual `publishes()` calls or using `spatie/package-skeleton-laravel` for a pre-configured package boilerplate. However, `laravel-package-tools` stands out for its fluent API, built-in `InstallCommand`, and support for modern Laravel features like view components. It’s the most comprehensive solution for reducing boilerplate in package development.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport