PHPackages                             filippo-toso/laravel-domain-library - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. filippo-toso/laravel-domain-library

ActiveLibrary[Framework](/categories/framework)

filippo-toso/laravel-domain-library
===================================

Build domain driven applications in Laravel

v4.0.1(2y ago)303752MITPHPPHP ^7.2.5|^8.0

Since Mar 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/filippotoso/laravel-domain-library)[ Packagist](https://packagist.org/packages/filippo-toso/laravel-domain-library)[ RSS](/packages/filippo-toso-laravel-domain-library/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (46)Used By (0)

Why does it exist?
==================

[](#why-does-it-exist)

I read the [Laravel Beyond CRUD](https://stitcher.io/blog/laravel-beyond-crud-01-domain-oriented-laravel) series and decided *this is the way*. But I'm a lazy coder: I really don't like to write a lot of code. So, I needed a toolkit to automate as much coding as possible. And here it is!

Requirements
------------

[](#requirements)

- PHP 7.2.5+
- Laravel 7+

Laravel 11 support
==================

[](#laravel-11-support)

I'm a little busy in this period. Laravel 11 has some critical changes that impact this package. In the next few days I'll try to find the time to make a new major release with full support for Laravel 11.

What it does?
-------------

[](#what-it-does)

It provides:

- multiple console commands to create domain driven classes
- traits and classes to speed up development

The commands prefix is `domain:`.

How does it work?
-----------------

[](#how-does-it-work)

Let's start with a clean Laravel installation. From your favorite shell:

```
composer create-project laravel/laravel project

```

Then install the library:

```
cd project
composer require filippo-toso/laravel-domain-library
composer require spatie/laravel-data spatie/laravel-model-states spatie/laravel-query-builder spatie/laravel-view-models

```

The additional Spatie's packages are required for data transfer objects, model states, query builders and view models.

Now the fun part... First, we are going to build the domain structure:

```
php artisan domain:setup:structure

```

This command will create a new `src` folder that will contain 3 namespaces `App`, `Domain` and `Support`. It will also rewire the Laravel application to work with this new directory structure (ie. moving middlewares and providers, updating the bootstrap code, introducing a new Application class, and so on).

At this point you can start building your domain driven application. Let's create the structure for a sample domain named `Invoices`

```
php artisan domain:make:domain Invoices

```

Then we will prepare the administrative application part for this domain:

```
php artisan domain:make:application Admin\Invoices

```

Making domain classes
---------------------

[](#making-domain-classes)

With this library you can make the following classes:

- Models (with support for custom collections, query builders and subscribed events)
- Model's states (using spatie/laravel-model-states)
- Model's subscribers and model events (automagically linked to models)
- Model's query builders (automagically loaded)
- Model's collections (automagically loaded)
- Data transfer objects (using spatie/data-transfer-object)
- HTTP queries (using spatie/laravel-query-builder)
- View models (using spatie/laravel-view-models)
- Actions
- Form requests

All the commands include a `--force` option to overwrite existing classes. Please keep in mind that *with great power comes great responsibility*

#### Customizing code generation

[](#customizing-code-generation)

If you want to customize the generated code, you can publish the stubs and then edit them.

```
php artisan vendor:publish --tag=stubs --provider="FilippoToso\Domain\Support\ServiceProvider"

```

#### Making models

[](#making-models)

```
php artisan domain:make:model Invoice --domain=Invoices

```

#### Making model's states

[](#making-models-states)

```
php artisan domain:make:states --model=Invoice --domain=Invoices --states="Paid,Pending,Overdue,Cancelled"

```

#### Making model's subscribers

[](#making-models-subscribers)

```
php artisan domain:make:subscriber --model=Invoice --domain=Invoices

```

#### Making model's events

[](#making-models-events)

```
php artisan domain:make:events --model=Invoice --domain=Invoices --events="saving,created,deleting"

```

#### Making model's subscribers and events

[](#making-models-subscribers-and-events)

```
php artisan domain:make:subscriber --model=Invoice --domain=Invoices --events="saving,created,deleting"

```

#### Making model's collections

[](#making-models-collections)

```
php artisan domain:make:collection --model=Invoice --domain=Invoices

```

#### Making model's query builders

[](#making-models-query-builders)

```
php artisan domain:make:querybuilder --model=Invoice --domain=Invoices

```

#### Making data transfer objects

[](#making-data-transfer-objects)

```
php artisan domain:make:dto Invoice --domain=Invoices --application=Admin\Invoices

```

#### Making HTTP queries

[](#making-http-queries)

```
php artisan domain:make:query InvoiceIndex --domain=Invoices --application=Admin\Invoices --model=Invoice

```

#### Making view models

[](#making-view-models)

```
php artisan domain:make:viewmodel InvoiceForm --domain=Invoices --application=Admin\Invoices --model=Invoice

```

#### Making actions

[](#making-actions)

```
php artisan domain:make:action InvoiceIndex --domain=Invoices --application=Admin\Invoices --model=Invoice

```

#### Making form requests

[](#making-form-requests)

```
php artisan domain:make:request Invoice --application=Admin\Invoices

```

#### Making exceptions

[](#making-exceptions)

```
php artisan domain:make:exception InvalidInvoice --domain=Invoices

```

### Making a suite of classes

[](#making-a-suite-of-classes)

This command will create all the classes above in a single sweep:

```
php artisan domain:make:suite
    --domain=Invoices
    --application=Admin\Invoices
    --model=Invoice
    --states="Paid,Pending,Overdue,Cancelled"
    --events="saving,created,deleting"
    --dtos="Invoice,CreateInvoice"
    --queries=InvoiceIndex
    --dtos="Invoice,CreateInvoice"
    --exceptions=InvalidInvoice
    --queries=InvoiceIndex
    --requests=Invoice
    --viewmodels=InvoiceForm
    --actions="CreateInvoice,PayInvoice,CancelInvoice"

```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~48 days

Total

45

Last Release

841d ago

Major Versions

v0.0.6 → v1.0.02021-03-08

v1.0.21 → v2.0.02022-03-04

v2.0.4 → v3.0.02023-03-05

v3.0.9 → v4.0.02023-10-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/55d89f2d44fb12225de2119994028ee69e36770bcf33c2b1ddf0d6672d28151b?d=identicon)[filippo.toso](/maintainers/filippo.toso)

---

Top Contributors

[![filippotoso](https://avatars.githubusercontent.com/u/26958813?v=4)](https://github.com/filippotoso "filippotoso (45 commits)")

### Embed Badge

![Health badge](/badges/filippo-toso-laravel-domain-library/health.svg)

```
[![Health](https://phpackages.com/badges/filippo-toso-laravel-domain-library/health.svg)](https://phpackages.com/packages/filippo-toso-laravel-domain-library)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spiral/framework

Spiral, High-Performance PHP/Go Framework

2.1k2.2M66](/packages/spiral-framework)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M194](/packages/laravel-ai)[laravel/surveyor

Static analysis tool for Laravel applications.

86121.4k11](/packages/laravel-surveyor)[contao/core-bundle

Contao Open Source CMS

1231.6M2.8k](/packages/contao-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
