PHPackages                             samir-hussein/laravel-cqrs - 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. samir-hussein/laravel-cqrs

ActiveLibrary[Framework](/categories/framework)

samir-hussein/laravel-cqrs
==========================

A clean CQRS (Command Query Responsibility Segregation) pattern implementation for Laravel applications

v1.0.0(2mo ago)08MITPHPPHP &gt;=8.0

Since Feb 20Pushed 2mo agoCompare

[ Source](https://github.com/samir-hussein/laravel-cqrs)[ Packagist](https://packagist.org/packages/samir-hussein/laravel-cqrs)[ RSS](/packages/samir-hussein-laravel-cqrs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (2)Used By (0)

Laravel CQRS Package
====================

[](#laravel-cqrs-package)

A clean and simple CQRS (Command Query Responsibility Segregation) pattern implementation for Laravel applications.

Features
--------

[](#features)

- ✅ **Simple &amp; Clean**: Easy to understand and implement
- ✅ **Auto-resolution**: Handlers are automatically resolved based on naming conventions
- ✅ **Laravel Integration**: Seamless integration with Laravel's service container
- ✅ **Type-safe**: Full type hints and interfaces
- ✅ **Flexible**: Works with any Laravel project structure
- ✅ **Validation Support**: Built-in validation methods for commands and queries
- ✅ **Middleware Pipeline**: Wrap handlers with middleware for logging, transactions, authorization, etc.
- ✅ **Universal Dispatch**: Single `dispatch()` method that works with both Commands and Queries

Installation
------------

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require samir-hussein/laravel-cqrs
```

The package will be automatically discovered by Laravel.

### Step 2: Publish Configuration (Optional)

[](#step-2-publish-configuration-optional)

```
php artisan vendor:publish --tag=cqrs-config
```

This creates `config/cqrs.php` where you can configure namespaces, middleware, and handler mappings.

### Step 3: Create Directory Structure (Optional)

[](#step-3-create-directory-structure-optional)

The package will create directories automatically when you use Artisan commands. Or create them manually:

```
app/
├── CQRS/
│   ├── Commands/
│   ├── Queries/
│   └── Handlers/

```

### Step 4: Use Artisan Commands (Recommended)

[](#step-4-use-artisan-commands-recommended)

The package includes Artisan commands to generate CQRS files:

```
# Create a command
php artisan cqrs:command User/CreateUserCommand

# Create a query
php artisan cqrs:query User/GetUserQuery

# Create a command handler
php artisan cqrs:handler User/CreateUserCommandHandler --type=command

# Create a query handler
php artisan cqrs:handler User/GetUserQueryHandler --type=query

# Create a pipeline middleware
php artisan cqrs:middleware User/TransactionMiddleware
```

That's it! You're ready to use the package.

Example 1: Creating and Using a Command
---------------------------------------

[](#example-1-creating-and-using-a-command)

This example shows how to create a command with validation and middleware support.

### 1. Create the Command

[](#1-create-the-command)

```
