Laravel Tactician is an implementation of the Command Bus Tactician by Ross Tuck.
Clone or download

Laravel Tactician

Laravel Tactician in an implementation of the Command Bus Tactician by Ross Tuck.

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight


To install this update your composer.json file to require

    "joselfonseca/laravel-tactician" : "0.3.*"

>= laravel5.5

ServiceProvider will be attached automatically


Once the dependencies have been downloaded, add the service provider to your config/app.php file

    'providers' => [

You are done with the installation!


To use the command bus you can resolve the bus from the laravel container like so

    $bus = app('Joselfonseca\LaravelTactician\CommandBusInterface');

Or you can inject it into a class constructor

    use Joselfonseca\LaravelTactician\CommandBusInterface;

    class MyController extends BaseController

        public function __construct(CommandBusInterface $bus)
            $this->bus = $bus;


Once you have the bus instance you can add your handler for the command to be dispatched

    $bus->addHandler('SomeCommand', 'SomeHandler');

Now you can dispatch the command with the middleware.

    // first parameter is the class name of the command
    // Second parameter is an array of input data to be mapped to the command
    // Third parameter is an array of middleware class names to be added to the stack
    $bus->dispatch('SomeCommand', [], []);

For more information about the usage of the tactician command bus please visit


Check out this example of the package implemented in a simple create order command


You can configure the bindings for the locator, inflector, extractor and default bus publishing the config file like so

    php artisan vendor:publish

Then you can modify each class name and they will be resolved from the laravel container

    return [
        // The locator to bind
        'locator' => 'Joselfonseca\LaravelTactician\Locator\LaravelLocator',
        // The inflector to bind
        'inflector' => 'League\Tactician\Handler\MethodNameInflector\HandleInflector',
        // The extractor to bind
        'extractor' => 'League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor',
        // The bus to bind
        'bus' => 'Joselfonseca\LaravelTactician\Bus'


You can generate Commands and Handlers automatically using artisan

artisan make:tactician:command Foo
artisan make:tactician:handler Foo

This will create FooCommand and FooHandler and place them in the app/CommandBus/Commands and app/CommandBus/Handlers respectively

To run both at once

artisan make:tactician Foo

Middleware included

Laravel tactician includes some useful middleware you can use in your commands

  • Database Transactions: This Middleware will run the command inside a database transaction, if any exception is thrown the transaction won't be committed and the database will stay intact, you can find this middleware in Joselfonseca\LaravelTactician\Middleware\DatabaseTransactions.

Change log

Please see the releases page


To run the test in this package, navigate to the root folder of the project and run

    composer install




Please see CONTRIBUTING for details.


If you discover any security related issues, please email jose at ditecnologia dot com instead of using the issue tracker.



The MIT License (MIT). Please see License File for more information.