I worked it out I worked out I could pass in any function to the mapping mapUsung function so I now setup the system to be able to find handlers in any package as long as it follows the same pattern of namespace /Commands for commands and namespace / handlers/commands for the handler class . Which suite my app better as Ive got a large application that has split different parts into there own packages as it lets me reuse them in other projects ..
apps4u said:
I worked it out I worked out I could pass in any function to the mapping mapUsung function so I now setup the system to be able to find handlers in any package as long as it follows the same pattern of namespace /Commands for commands and namespace / handlers/commands for the handler class . Which suite my app better as Ive got a large application that has split different parts into there own packages as it lets me reuse them in other projects ..
Any chance you could post a code example of what you ended up writing?
Ah ha, found your GitHub issue about this - https://github.com/laravel/framework/issues/8061
I ended up with something kind of similar
<?php
namespace App\App\Providers;
use Illuminate\Bus\Dispatcher;
use Illuminate\Support\ServiceProvider;
class BusServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @param \Illuminate\Bus\Dispatcher $dispatcher
* @return void
*/
public function boot(Dispatcher $dispatcher)
{
$dispatcher->mapUsing(function ($command) {
$handler = str_replace('\\Commands\\', '\\Handlers\\', get_class($command));
$handler .= 'Handler@handle';
return $handler;
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community