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/ */
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
}
}