Looking to hire Laravel developers? Try LaraJobs

laravel-domains maintained by pushberryfinn

Description
A Laravel package to manage and create modular domains inside your app
Last update
2026/05/10 05:13 (dev-main)
License
Downloads
15

Comments
comments powered by Disqus

Laravel Domains

Latest Version on Packagist Tests License PHP Version

A Laravel package to manage and create modular domains inside your Laravel app.

Overview

This package helps you organise your Laravel application by grouping related code (models, controllers, migrations, routes, commands, etc.) into domains — self-contained folders under app/Domains. Routes, migrations, and commands are automatically discovered and loaded for each domain.


Requirements

  • PHP 8.2 or higher
  • Laravel 11.x

Installation

composer require pushberryfinn/laravel-domains

Optionally publish the config file:

php artisan vendor:publish --tag=laravel-domains-config

Usage

Create a domain

php artisan domain:make Doctors

This creates the following structure under app/Domains:

app/Domains/
├── DomainsServiceProvider.php   ← created once on first domain
└── Doctors/
    ├── Console/Commands/
    ├── Http/Controllers/
    ├── Http/Requests/
    ├── Models/
    ├── database/migrations/
    └── routes/api.php

Important: After running domain:make for the first time, register DomainsServiceProvider in bootstrap/providers.php:

return [
    App\Providers\AppServiceProvider::class,
    App\Domains\DomainsServiceProvider::class,
];

Generate domain resources

# Model
php artisan domain:make-model Doctor --domain=Doctors

# Controller
php artisan domain:make-controller DoctorController --domain=Doctors

# Form Request
php artisan domain:make-request StoreDoctorRequest --domain=Doctors

# Migration
php artisan domain:make-migration create_doctors_table --domain=Doctors

# Artisan command
php artisan domain:make-command SyncDoctors --domain=Doctors

How it works

  • Every folder inside app/Domains is treated as a domain.
  • DomainsServiceProvider (placed in app/Domains) automatically loads each domain's migrations, routes, and console commands.
  • Console commands placed in {Domain}/Console/Commands/ are auto-registered.

Facade

You can use the LaravelDomains facade to list all registered domains at runtime:

use LaravelDomains;

$domains = LaravelDomains::domains(); // ['Doctors', 'Patients', ...]

License

The MIT License (MIT). See the LICENSE file for details.


Author

Atdhe Krasniqi — GitHub