Search by

supplycart / domains

sc.super

Domain Manager

Package info

github.com/supplycart/domains

pkg:composer/supplycart/domains

Statistics

Installs: 55 892

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

2.0.0 2026-09-03 02:15 UTC

README

A lightweight, route-focused domain registry for Laravel 13.

The package keeps domain bootstrapping deliberately small: it registers each domain's routes, while Laravel handles events, model observers, and authorization policies through its native discovery and attribute APIs. When routes are cached, the configured domains are not loaded at all.

Requirements

  • PHP 8.5 or later
  • Laravel 13

Installation

Install the package and publish its configuration:

composer require supplycart/domains:^2.0
php artisan vendor:publish --tag=domains-config

Creating a domain

Generate a domain with Artisan:

php artisan make:domain User

This creates the domain under app/Domains/User, including its domain class, model, policy, controller, and routes file.

Register the generated domain class in config/domains.php:

<?php

declare(strict_types=1);

use App\Domains\User\User;

return [
    'modules' => [
        User::class,
    ],
];

The generated domain owns its route registration:

<?php

declare(strict_types=1);

namespace App\Domains\User;

use Supplycart\Domains\Domain;

final class User extends Domain
{
    public static function registerRoutes(): void
    {
        require __DIR__.'/Http/routes.php';
    }
}

Domains without routes can inherit the default no-op implementation.

Queued scaffolding

Use the --queues option to also generate an event, a discoverable listener, and a queued job:

php artisan make:domain User --queues

Discover domain listeners from bootstrap/app.php:

->withEvents(discover: [
    __DIR__.'/../app/Domains/*/Listeners',
])

The generated model is linked to its policy with Laravel's #[UsePolicy] attribute. Register model observers with Laravel's #[ObservedBy] attribute.

Production optimization

Run Laravel's optimizer during deployment or image creation:

php artisan optimize

Once routes are cached, the package skips the configured domain list entirely.

Upgrading from version 1

Version 2 removes domain-level $listeners, $observers, $policies, init(), and reflection-based route discovery. When upgrading:

  • Move listeners to Laravel event discovery.
  • Register observers with #[ObservedBy].
  • Register policies with #[UsePolicy].
  • Implement registerRoutes() explicitly in domains that own routes.