1. Go to this page and download the library: Download b7s/laravel-queue-flow 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/ */
b7s / laravel-queue-flow example snippets
// Dispatch automatically One item
qflow(fn () => $this->doOtherThing());
// Dispatch automatically multiple items with array of closures
qflow([
fn () => $this->doOtherThing(),
fn () => $this->doMoreThings(),
// ...
]);
// Dispatch manually (set autoDispatch to false) after configuration
qflow(fn () => $this->doOtherThing(), autoDispatch: false)
->onQueue('high-priority')
->shouldBeUnique()
->shouldBeEncrypted()
->rateLimited('default')
->onFailure(function () {
// Your logic here
})
->dispatch();
// Dispatch multiple items with returns a Collection of PendingDispatch objects,
// then, apply middleware to each dispatch
qflow([
fn () => $this->callExternalApi(),
fn () => $this->callExternalApi(),
])
// Apply middleware to each dispatch
->each(fn ($dispatch) => $dispatch->through([new \Illuminate\Queue\Middleware\RateLimited('api-calls')]));
use B7s\QueueFlow\Queue;
class TestQueueController
{
private Queue $myQueue;
public function __construct()
{
$this->myQueue = new Queue();
}
public function doSomething(): void
{
// Will auto-dispatch when $this->myQueue goes out of scope
$this->myQueue->add(fn () => $this->doOtherThing());
}
}
use B7s\QueueFlow\Queue;
class ReportService
{
public function __construct(
private readonly Queue $queue,
) {
}
public function generate(): void
{
$this->queue
->add(fn () => $this->buildReport())
->dispatch();
}
}