jildertmiedema / laravel-tactician
适用于laravel 8+的Tactician
V0.6.0
2024-01-19 10:47 UTC
Requires
- php: >=8.1.0
- illuminate/support: ^10.0
- league/tactician: ^1.0
Requires (Dev)
- laravel/framework: ^10.0
- phpunit/phpunit: ^10.0
README
laravel 5+的Tactician命令总线
安装
composer require jildertmiedema/laravel-tactician
将 JildertMiedema\LaravelTactician\TacticianServiceProvider
添加到你的 app.php 文件中
在命令行中运行以下命令
php artisan vendor:publish
编辑 config/tactician.php
并设置你的命名空间
用法
在你的控制器或控制台命令中,你可以使用特质 JildertMiedema\LaravelTactician\DispatchesCommands
。
use YourApp\Commmands\DoSomethingCommand; use Illuminate\Routing\Controller as BaseController; use JildertMiedema\LaravelTactician\DispatchesCommands; class Controller extends BaseController { use DispatchesCommands; public function store(Request $request) { $command = new DoSomethingCommand($request->get('id'), $request->get('value')); $this->dispatch($command); return redirect('/'); } }
扩展
中间件
在你的自己的 ServiceProvider 中
$this->app['tactician.middleware']->prepend('your.middleware'); $this->app->bind('your.middleware', function () { return new MiddleWare });
定位器
默认定位器由 tactician.handler.locator
在容器中设置,当然你也可以更改它。
在你的自己的 ServiceProvider 中
$this->bind('tactician.handler.locator', function () { return new YourLocator(); });