Support the ongoing development of Laravel.io →
Requests Jobs
Last updated 1 month ago.
0

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 ..

0

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?

0

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 .= '[email protected]';
            return $handler;
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
0

Sign in to participate in this thread!

LoadForge

Your banner here too?

apps4u apps4u apps4u Joined 7 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.