PHP code example of assetplan / dispatcher

1. Go to this page and download the library: Download assetplan/dispatcher library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

assetplan / dispatcher example snippets



'aliases' => [
    'send-welcome-email' => 'App\Jobs\SendWelcomeEmail',
],


    $dispatcher->dispatch('send-welcome-email', ['user' => $user]);



use Assetplan\Dispatcher\Dispatcher;
use Illuminate\Http\Request;

class ExampleController
{
    public function store(Request $request, Dispatcher $dispatcher)
    {
        $result = $dispatcher->dispatch(MyJob::class, ['foo' => 'bar']);
        if ($result->failed()) {
            // do something if failed dispatch
        }

        return $result->getId(); // the result object allows access to the dispatched job id
    }
}



use Assetplan\Dispatcher\Dispatcher;
use App\Jobs\SendWelcomeEmail;
use Illuminate\Http\Request;

class ExampleController
{
    public function store(Request $request, Dispatcher $dispatcher)
    {
        $jobs = [
            new Job(
                SendWelcomeEmail::class,
                ['email'=>'[email protected]']
            ),
            new Job(
                'App\Jobs\InviteToUserGroup',
                ['email'=>'[email protected]']
            ),
        ];
        $result = $dispatcher->batch($jobs, 'emails', shouldBatch: true);
        if ($result->failed()) {
            // do something if failed dispatch
        }

        return $result->getId(); // the result object allows access to the dispatched batch id
    }
}

bash
php artisan dispatcher:generate-secret
bash
php artisan dispatcher:generate-secret --length=128
bash
php artisan dispatcher:generate-secret --no-replace
bash
php artisan vendor:publish --provider="Assetplan\Dispatcher\DispatcherServiceProvider" --tag="config"