NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Package Toolkit for Laravel

The package builder

Extend PackageServiceProvider and describe what your package ships in configurePackage(). Everything console-gated is wired for you:

use RoundlyConsulting\PackageToolkit\Package;
use RoundlyConsulting\PackageToolkit\PackageServiceProvider;

final class CommentsServiceProvider extends PackageServiceProvider
{
    public function configurePackage(Package $package): void
    {
        $package
            ->name('comments')
            ->hasConfigFile()
            ->hasMigrations()
            ->hasTranslations()
            ->hasCommands([PruneCommentsCommand::class])
            ->contributesToAbout();
    }
}

Where the package root is

The base provider computes the package root from the provider’s own location: src/…ServiceProvider.php → the package root, the directory that holds config/, database/, resources/ and routes/. Every builder path resolves relative to it:

comments-for-laravel/
    config/comments.php                 hasConfigFile()
    database/migrations/*.php           hasMigrations()
    database/migrations/<name>.php.stub hasMigration('<name>')
    resources/lang/                     hasTranslations()
    resources/views/                    hasViews()
    routes/<file>                       hasRoutes('<file>')
    src/CommentsServiceProvider.php     the provider — the package root is the directory above src/

For a non-standard layout — a provider nested deeper than src/, for example — override resolvePackageBasePath():

// src/Providers/CommentsServiceProvider.php — one level deeper than usual
protected function resolvePackageBasePath(): string
{
    return dirname(__DIR__, 2);
}

What the base provider does

  • register() — creates the Package with the resolved base path, calls configurePackage(), merges every declared config file and registers the declared class aliases (an unrecognised alias value throws).
  • boot() — loads translations and views, loads route files (unless their config switch reads as false; an unrecognised switch value throws) and adds the about contributions.
  • boot(), console only — registers every publish group (config, migrations, translations, views, routes, stubs) and the console commands.

Each step is a protected method — registerPackageConfig(), registerFacadeAliases(), bootPackage(), registerAboutContributions(), bootPackageInConsole() and publishPackageMigrations() — so a package with an unusual need overrides exactly one step instead of the whole provider.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.