---
title: "The package builder — Package Toolkit for Laravel | Roundly"
description: "Extend PackageServiceProvider, describe your package in configurePackage(), and let the base provider wire the rest."
url: https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel/package-builder
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Package Toolkit for Laravel](https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel.md)

# The package builder

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

```php
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():

```php
// 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 — the host’s published copy when there is one — 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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel.md)
